Some common functions:
1) turtle.pensize (): Set the thickness of the line;
2) Turtle.speed (): Set the speed of drawing, 1-10,1 slowest, 10 fastest;
3) Turtle.begin_fill (): Ready to start filling graphics;
4) Turtle.circle (50,steps=3): Circle function used before, is to draw a radius of radius of the circle, here is the extension, steps represents the radius of 50 in the circle of the built-in steps polygon;
5) Turtle.end_fill (): Fill complete;
6) Turtle.write (s,font= ("Font-name", Font_size, "Font_type"): Write text, s for text, font is the parameter of font, which is the font name, size and type respectively;
7) Turtle.hideturtle (): Hidden arrows display;
8) Turtle.backward (d): corresponds to the Forward () function, which draws lines and arrows from the tail to the head;
9) Turtle.left (angle): counterclockwise rotation of the direction of the arrow;
Turtle.undo (): Undo the last turtle action;
One) turtle.screensize (w,h): Set the length and width of the turtle window;
Turtle.clear (): Empty the Turtle window, but turtle position and status will not change;
Turtle.reset (): Clears the window, resets the turtle state to the starting State;
Turtle.showturtle (): Corresponds to the hideturtle () function;
Turtle.filling (): Returns whether the current is in the fill state; True is filling,false to not filling;
Turtle.isvisible (): Returns whether the current turtle is visible.
Turtle.pos ():
Example:
#画太阳花
Import Turtle
import time
turtle.color (' Red ', ' yellow ')
Turtle.begin_fill () while
True:
Turtle.forward
turtle.left (170)
If ABS (Turtle.pos ()) < 1: Break
Turtle.end_fill ()
turtle.done ()
time.sleep (10)
As shown in figure:
Draw the Pentagram:
#绘制五角星
Import Turtle
import time
turtle.fillcolor (' red ')
Turtle.begin_fill () while
True:
Turtle.forward
turtle.right (144)
If ABS (Turtle.pos ()) < 1: Break
Turtle.end_ Fill ()
time.sleep (20)
As shown in figure:
To draw a colored helix:
#绘制彩色螺旋线
Import Turtle
import time
turtle.pensize (2)
Turtle.bgcolor ("black")
colors = ["Red", " Yellow "," purple "," blue "]
turtle.tracer (False) for
x in range ():
turtle.forward (2*x)
Turtle.color (colors[x% 4])
Turtle.left ($)
turtle.tracer (True)
# input () can effectively resolve the flicker problem, or the following method
Time.sleep (20)
As shown in figure: