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.
Basic knowledge of turtle drawing:
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

To run Python code in Sublime Text, you need to install the Python plug-in first, then create a .py file and write the code, and finally press Ctrl B to run the code, and the output will be displayed in the console.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Golang is better than Python in terms of performance and scalability. 1) Golang's compilation-type characteristics and efficient concurrency model make it perform well in high concurrency scenarios. 2) Python, as an interpreted language, executes slowly, but can optimize performance through tools such as Cython.

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

Running Python code in Notepad requires the Python executable and NppExec plug-in to be installed. After installing Python and adding PATH to it, configure the command "python" and the parameter "{CURRENT_DIRECTORY}{FILE_NAME}" in the NppExec plug-in to run Python code in Notepad through the shortcut key "F6".
