Home >Backend Development >Python Tutorial >What is the function of turtle.done()
In Python, the function of "turtle.done()" is to pause the program and stop the brush drawing, but the drawing form will not close until the user closes the Python Turtle graphical window; its purpose is to give the user time to view the graph; without it, the graph window will close as soon as the program completes.
#The operating environment of this tutorial: Windows 7 system, Python 3 version, Dell G3 computer.
The role of turtle.done(): pause the program and stop brush drawing, but the drawing form will not close until the user closes the Python Turtle graphical window.
The Turtle library is a very popular function library for drawing images in the Python language. Imagine a little turtle, at the origin of a coordinate system with the horizontal axis as x and the vertical axis as y, (0,0 ) position, it moves in this plane coordinate system according to the control of a set of function instructions, thereby drawing graphics on the path it crawls.
1. Canvas
The canvas is the turtle that expands the drawing area for us. We can set its size and initial position.
Set the canvas size
turtle.screensize(canvwidth=None, canvheight=None, bg=None), the parameters are the width of the canvas (unit pixels), height, background color.
For example: turtle.screensize(800,600, "green")
## Turtle.screensize() #Return to the default size (400, 300)
turtle.setup(width=0.5, height=0.75, startx=None, starty=None), parameters: width, height: When the input width and height are integers, Represents pixels; when it is a decimal, it represents the proportion of the computer screen occupied, (startx, starty): This coordinate represents the position of the upper left corner of the rectangular window. If it is empty, the window is located at the center of the screen.
. =800, startx=100, starty=100)
2. Brush
2.1 The status of the brush
On the canvas, there is a coordinate axis whose coordinate origin is the center of the canvas by default, and there is a surface on the coordinate origin The little turtle faces the positive direction of the x-axis. Here we use two words to describe the little turtle: coordinate origin (position), facing the positive direction of the x-axis (direction). In turtle drawing, the position and direction are used to describe the state of the little turtle (brush).
2.2 Brush properties
Brush (Brush properties, color, line drawing The width of the brush, etc.)
1) turtle.pensize(): Set the width of the brush;
2) turtle.pencolor(): None The parameters are passed in, and the current brush color is returned. The parameters passed in set the brush color, which can be strings such as "green", "red", or RGB 3-tuples.
3) turtle.speed(speed): Set the brush movement speed, the brush drawing speed range is [0,10] integer, the larger the number, the faster.
2.3 Drawing commands
There are many commands to control turtle drawing. These commands can It is divided into 3 types: one is the motion command, one is the brush control command, and the other is the global control command.
(1) Brush movement command
##Command
Description |
##turtle.forward(distance) |
Move the distance pixel length toward the current brush direction |
##turtle.backward(distance) |
Move the distance pixel length in the opposite direction of the current brush |
|
# #turtle.right(degree)
|
Move degree°clockwise
|
|
turtle.left(degree)
|
Move degree° counterclockwise
|
|
turtle.pendown()
|
Draw graphics when moving, and also draw by default
|
|
turtle.goto(x,y)
|
Move the brush to the coordinates of x,y Location
|
|
Draw a circle with a positive (negative) radius, which means the center of the circle is to the left (right) of the brush |
|
|
Move the current x-axis to the specified position |
|
|
Move the current y-axis to the specified position |
|
|
Set the current heading to angle angle |
||
Set the current brush position to the origin, facing east. |
||
Draw a specified diameter and color dots |
Description |
| turtle.fillcolor(colorstring)||||||||||||||||||||||||||
##The fill color of drawing graphics |
turtle.color(color1, color2) |
||||||||||||||||||||||||||
Also set pencolor=color1, fillcolor=color2 |
##turtle.filling() |
||||||||||||||||||||||||||
Returns whether the current In the fill state |
turtle.begin_fill() |
||||||||||||||||||||||||||
Prepare to start filling the graphics |
##turtle.end_fill() |
||||||||||||||||||||||||||
Filling completed
|
turtle.hideturtle() |
||||||||||||||||||||||||||
Hide the turtle shape of the brush
|
##turtle.showturtle() |
||||||||||||||||||||||||||
##Command |
Description |
##turtle.clear()
| Clear the turtle window, but the turtle's position and status will not change
|
Returns whether the current turtle is visible |
|
Copy the current graphic |
|
Write text, s is the text content, font is the parameter of the font, which are the font name, size and type respectively; font is optional, and the font parameter is also optional |
##Description |
##turtle.mainloop() or turtle.done() |
Start the event loop - |
Call the mainloop function of Tkinter. # must be the last statement in the turtle graphics program. ##turtle.mode(mode=None) |
Set turtle mode ( "standard" | ,
"logo" or "world ”) and perform a reset. If no mode is given, returns the current mode. Mode initial turtle title positive angle standard right (east) counterclockwise logo upward (north) clockwise turtle.delay(delay=None) |
Set or return the drawing delay in milliseconds. |
##turtle.begin_poly() |
Start recording the vertices of the polygon. The current turtle position is the first vertex of the polygon.
|
##turtle.end_poly() |
##turtle.get_poly() | |
The above is the detailed content of What is the function of turtle.done(). For more information, please follow other related articles on the PHP Chinese website!