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!

TomergelistsinPython,youcanusethe operator,extendmethod,listcomprehension,oritertools.chain,eachwithspecificadvantages:1)The operatorissimplebutlessefficientforlargelists;2)extendismemory-efficientbutmodifiestheoriginallist;3)listcomprehensionoffersf

In Python 3, two lists can be connected through a variety of methods: 1) Use operator, which is suitable for small lists, but is inefficient for large lists; 2) Use extend method, which is suitable for large lists, with high memory efficiency, but will modify the original list; 3) Use * operator, which is suitable for merging multiple lists, without modifying the original list; 4) Use itertools.chain, which is suitable for large data sets, with high memory efficiency.

Using the join() method is the most efficient way to connect strings from lists in Python. 1) Use the join() method to be efficient and easy to read. 2) The cycle uses operators inefficiently for large lists. 3) The combination of list comprehension and join() is suitable for scenarios that require conversion. 4) The reduce() method is suitable for other types of reductions, but is inefficient for string concatenation. The complete sentence ends.

PythonexecutionistheprocessoftransformingPythoncodeintoexecutableinstructions.1)Theinterpreterreadsthecode,convertingitintobytecode,whichthePythonVirtualMachine(PVM)executes.2)TheGlobalInterpreterLock(GIL)managesthreadexecution,potentiallylimitingmul

Key features of Python include: 1. The syntax is concise and easy to understand, suitable for beginners; 2. Dynamic type system, improving development speed; 3. Rich standard library, supporting multiple tasks; 4. Strong community and ecosystem, providing extensive support; 5. Interpretation, suitable for scripting and rapid prototyping; 6. Multi-paradigm support, suitable for various programming styles.

Python is an interpreted language, but it also includes the compilation process. 1) Python code is first compiled into bytecode. 2) Bytecode is interpreted and executed by Python virtual machine. 3) This hybrid mechanism makes Python both flexible and efficient, but not as fast as a fully compiled language.

Useaforloopwheniteratingoverasequenceorforaspecificnumberoftimes;useawhileloopwhencontinuinguntilaconditionismet.Forloopsareidealforknownsequences,whilewhileloopssuitsituationswithundeterminediterations.

Pythonloopscanleadtoerrorslikeinfiniteloops,modifyinglistsduringiteration,off-by-oneerrors,zero-indexingissues,andnestedloopinefficiencies.Toavoidthese:1)Use'i


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

Dreamweaver CS6
Visual web development tools

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

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver Mac version
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!
