Drawing graphics from the Turtle library in Python

Source: Internet
Author: User

1. Prelude:

When drawing with turtle, you need to install the corresponding Python interpreter and IDE, I installed Pycharm, after installing Pycharm, in Pycharm install the corresponding library module, drawing can introduce turtle module, You can introduce NumPy modules if you want to perform operations.
Note: Turtle is not supported in Pycharm, it may be a problem of dynamic language.
The functions commonly used in turtle drawing are:

: Manipulating turtle drawings There are many commands that can be divided into two types: one for the motion command, one for the Brush Control command
(1) for the Brush Motion command:
Command description
Turtle.forward (distance) Move distance pixels to the current brush direction
Turtle.backward (distance) moves in the opposite direction of the current brush distance pixel length
Turtle.right (degree) move clockwise degree°
Turtle.left (degree) moves counterclockwise degree°
Turtle.pendown () to draw a graphic, and, by default, to draw
Turtle.goto (x, y) to move the brush to the location of x, y coordinates
Turtle.penup () Moves without drawing the drawing, lifting the pen, and drawing the speed range [0,10] integer
turtle.circle () drawn with the
Turtle.speed (velocity) brush for another place to draw a circle with a positive (negative) radius. Indicates that the center is on the left side of the brush (right) draw a circle
(2) Brush control command:
Command description
turtle.pensize width When drawing a drawing
Turtle.pencolor () Brush color
Turtle.fillcolor (colorstring) Draw the fill color of a graphic
Turtle.color (Color1, Color2) while setting Pencolor=color1, Fillcolor=color2
Turtle.filling () returns whether the current fill state
Turtle.begin_fill () prepares to begin filling the drawing
Turtle.end_fill () fill is complete;
Turtle.hideturtle () The hidden arrows are displayed;
Turtle.showturtle () corresponds to the Hideturtle () function

(3) Global control commands
Command description
Turtle.clear () Clears the Turtle window, but the position and state of the turtle do not change
Turtle.reset () Clears the window, resets the turtle state to the start state
Turtle.undo () Undo Last turtle Action
Turtle.isvisible () returns whether the current turtle is visible
Stamp () Copy the current drawing
Turtle.write (s[,font= ("Font-name", Font_size, "Font_type")]) writes the text, S is the text content, the font is the typeface parameter, inside is the font name, the size and the type, respectively, the font is optional, The parameters of the font are also optional

2. What needs to be stated

(1): On the canvas, the default is a coordinate origin of the center of the canvas axis, the coordinates of the origin of a face toward the x-axis square to the small turtle. Here we describe the little turtle using two words: coordinates origin (position), face to the x-axis positive direction (direction), turtle drawing, is to use the position direction to describe the small turtle (brush) state This command is Goto ();
(2): turtle.circle (RADIUS, Extent=none, Steps=none) Description: Draw a circle at a given radius
Parameters:
Radius (RADIUS); The radius is positive (negative), which indicates that the center circle is drawn on the left (right) of the brush
Extent (radians) (optional);
Steps (optional) (the inner tangent regular polygon of a circle radius radius, the number of polygon edges is steps)
Example:
Circle (50) # Full Circle;
Circle (50,steps=3) # triangle;
Circle (120, 180) # semicircle

(3) filling Start_fill () End_fill ()
Null parameter indicates the content color of the fill at the end of a brush motion state

3. Specific examples:

Draw a square

4. Draw the Pentagram

    1. Draw Java Coffee

Drawing graphics from the Turtle library in Python

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.