Python Notes _ The first article _ Lad Gong _8. Drawing tools (small turtle turtle)

Source: Internet
Author: User

Turtle is a simple drawing tool.

Provide a small turtle, can be understood as a robot, only understand the limited command, and the drawing window of the origin (0,0) in the middle, the default turtle direction is the right side
Turtle commands include three classes: motion commands, stroke control commands, and other commands .

1. Motion Commands
Forward (d): Move forward D length (start on right)
Backward (d): Move backward D length
Right (d): How many degrees of rotation
Left (d): How many degrees to rotate
Goto (x, y): Moves to the location of the specified (x, y) axis
Turtle.clear () # Situation window, does not reset turtle
Turtle.reset () # Reply to all settings, clear windows, reset Turtle Status
Speed (): The rate at which the Little turtle moves

2. Stroke control Commands
Circle (r,e) Draws a circle, R is the radius, E is the degree, the full circle is 365 degrees, can also steps= 4, with the number of steps to represent. The corresponding three values are: radius (RADIUS), extent (radians) (optional), Steps (optional) (RADIUS radius of the inner tangent regular polygon, Polygon edge number is steps)
Up () stroke lifted, no drawing after moving
Down () Stroke direction
Setheading (d) resetting the direction of the baby turtle
Width of the pensize (width) brush
Color of the PenColor (COLORSTR) Brush

Begin_fill () # Fill command start
FillColor (COLORSTR) # Fill Color
End_fill () # End Fill

3. Other commands
Done (): program continues execution
Undo (): Undo Last Action
Hideturtle (): Hide turtles
Showturtle (): Show turtles
ScreenSize (x, y): Screen size

  Example 1:

1Turtle.screensize (1000, 100)#Setting the screen size2Turtle.forward (10)#move forward (right) 10 steps3Turtle.undo ()#undo the previous step4Turtle.forward (100)#move forward (right) 100 steps5Turtle.undo ()#undo the previous step6Turtle.hideturtle ()#Hide the Little Turtle (cursor)7Turtle.showturtle ()#Show the Little Turtle (cursor)8Turtle.clear ()#situation window, does not reset turtle9Turtle.reset ()#reply to all settings, clear windows, reset Turtle statusTenTurtle.done ()#continue-This is typically loaded at the end of a small turtle, saving the graphic save. 

  Example 2: The associated run instruction, draw a rectangle with the forward and left commands.

1 #Example 2:2 #related motion commands draw a rectangle with the forward and left commands3Turtle.forward (100)4Turtle.left (90)5Turtle.forward (100)6Turtle.left (90)7Turtle.forward (100)8Turtle.left (90)9Turtle.forward (100)Ten Turtle.hideturtle () OneTurtle.done ()

Display Graphics:

Example 3:

1 # Move Backwards 2 # rotate right How many degrees 3 # move to the specified (x, y) 4 # the speed of the Little turtle moving 5 Turtle.done ()

Display Graphics:

Example 4:

1Turtle.speed (1.5)2Turtle.pensize (10)3Turtle.pencolor ("Black")4Turtle.begin_fill ()#Start filling5Turtle.circle (steps=, 10)6Turtle.fillcolor ("Blue")#Fill Color7Turtle.end_fill ()#End Fill8 turtle.up ()9 Turtle.down ()TenTurtle.setheading (30) OneTurtle.done ()

Display Graphics:

Python Notes _ The first article _ Lad Gong _8. Drawing tools (small turtle turtle)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.