Drawing using Python's Turtle (Turtle) module

Source: Internet
Author: User

Using Python'sTurtle (Turtle)Module drawing the first step: let Python introduce the Turtle module, the introduction of the module is to tell Python you want to use it.
Import Turtle

Step Two: Create the canvas. Call the pen function in turtle.
t = Turtle. Pen ()

Step three: Move the turtle.
T.forward (50)

Forward's Chinese meaning is "forward, promote." So this line of code means that the turtle moves forward 50 pixels :

T.left (90)

Let the turtle turn left 90 degrees.

Now we can try to draw a square, the idea is to move forward-to 90 degrees-forward, cycle four times.

>>> t.forward >>> t.left(all)>>> t.forward (+) >> > T.left >>> t.forward (+) >>> t.left(+) >>> t,forward( >>>t.left (+)>>> T,forward (50)

The effect is as follows:

Fourth step: Erase the canvas.
>>> T.reset ()

Reset Command (reset) This clears the canvas and puts the turtle back where it started.

>>> T.clear ()

Clear clears the screen only, and the turtle remains in its original position.

We can also make the turtle turn right or let it go back (backward). We can use up to lift the pen from the paper (in other words, let the turtle stop painting) and start the painting with a downward (down) .

Below we use a comprehensive, draw two lines.
>>> t.reset ()  // erase the canvas and move the turtle back to its starting position >>> T.backward (  +)// back 100 pixels > >> t.up ()  // pen no longer painting >>> t.right  //Turn right 90 degrees >>> T.forward ( )  // forward 20 pixels >>> t.left (total)  // turn left 90 degrees >>> t.down ()  //  Pen ready to paint >>> T.forward (  +)//forward 100 pixels

The effect is as follows:

Summarize

Just beginning to learn to use the Turtle module painting, it feels like elementary school just started painting. Once a pen was drawn directly on paper, and now using Python to paint, the feeling was to break away from the previous painting: Prepare the canvas--pick up the pen to paint--start painting--put down the pen and stop painting. It's fun, slow down, it's just the beginning. ^_^

Drawing using Python's Turtle (Turtle) module

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.