Turtle Library Introduction
1. The Turtle.setup () function in turtle is used to start a graphics window with four parameters
Turtle.setup (width, height, startx, starty)
is: The width and height of the start window represents the coordinate position of the upper-left corner of the window in the screen when the window starts.
The display screen we use is also a coordinate system thatThe upper-left corner is the origin, and the left and down are the X and y axes, respectively. Python program code launches a 1300-pixel wide, 800-pixel-high window The upper-left corner of the window is the upper- left corner of the screen.
(Startx,starty) represents the initial point of the drawing, (0,0) in the center of the computer screen
2. The Turtle.pensize () function in turtle indicates the small turtle motion trajectory the width.
3, turtle the Turtle.pencolor () function represents the small turtle motion trajectory
it contains an input parameter, where we set it to blue,other color words can also be used. Turtle uses RGB to definecolor, if you want to get a small snake that matches the color in your picture, enterTurtle.pencolor ("#3B9909")
4, turtle turtle.seth (angle) function means the small turtle starts The direction of the movement. It contains an input parameter, which is the angle value.
of these, 0 means eastward, 90 degrees northward, 180 degrees westward, 270 degrees tonegative indicates the opposite direction. program, we let the small turtle to 40 degrees to start crawling, namely: to the Southeastdirection 40 degrees.
5, turtle.circle () function let the little turtle crawl along a circle
parameter rad describes the position of the circular trajectory radius, This radius is on the left side of the small turtle run, rad far away. if rad is negative, the radius is on the right side of the small turtle run, the parameter angle represents the Radian value of the small turtle crawling along the circle.
6,turtle.fd () function can also be used Turtle.forward () to indicate that the turtle to the front line crawling movement , the small turtle to move straight forward,
It has a parameter that indicates that crawling the distance of the line
Procedure 1
Import turtledef Drawsnake (Rad,angle,num,neckrad): forIinchrange (num): turtle.circle (Rad,angle) turtle.circle (-rad,angle) turtle.circle (Rad,angle/2) TURTLE.FD (RAD) turtle.circle (Neckrad+1, the) TURTLE.FD (Rad*2/3) def main (): Turtle.setup (1300, -,0,0) Pythonsize= -turtle.pensize (pythonsize) Turtle.pencolor ('Blue') Turtle.seth (- +) Drawsnake ( +, the,3, pythonsize/2) Main ()
2. Change the color
Application of Python Turtle Library--Snake