Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How Python draws Rose and Page

Shulou Source: shulou.com Published: 2022-06-01 07:57:09 10月01日 Update

This article will explain in detail how Python draws roses and Page. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

1 introduction to turtle Library

Turtle library is a very popular function library for drawing images in Python language. imagine a small tortoise starting at the origin of a coordinate system with a horizontal axis of x and a vertical axis of y.

It moves in this plane coordinate system according to the control of a set of function instructions, thus drawing a figure on its crawling path.

2 brushes

On the canvas, by default, there is a coordinate origin that is the coordinate axis of the center of the canvas, and there is a small turtle facing in the positive direction of the x axis on the coordinate origin. Here we use two words to describe the little tortoise: the coordinate origin (position), facing the positive direction of the x-axis (direction), and in turtle drawing, the position direction is used to describe the state of the little tortoise (brush).

Brush (properties of the brush, color, width of lines, etc.)

Turtle.pensize (): sets the width of the brush

Turtle.pencolor (): no parameter is passed, the current brush color is returned, and the parameter is passed to set the brush color, which can be a string such as "green", "red", or a RGB 3 tuple.

Urtle.speed (speed): sets the speed of brush movement. The speed range of brush painting is an integer. The larger the number, the faster the number.

3 drawing command

There are many commands to manipulate tortoise drawing, which can be divided into three types: one is motion command, one is brush control command, and the other is global control command.

Explain several commonly used motion commands:

Forward (100): move 100 pixels in the current brush direction

Right (90): move 90 degrees clockwise

Left (90): move 90 degrees counterclockwise

Goto (XBI y): move to XBI y

Circle (), dot (): draw circles and dots, respectively

Brushes and global commands:

Fillcolor (colorstring): fill color for drawing a graph

Clear (): clear the turtle window

4 examples

1 draw quadrilateral

2 draw a cross

3 sunflowers

4 roses

5 Piglet Paige

This is the end of the article on "how to draw roses and Page in Python". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Brush command coordinate move tortoise direction origin color rose page position article control drawing global function parameter graphics coordinate system width Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Technology Microsoft NVidia Apple