Python Learning (i) Turtle drawing __python

Source: Internet
Author: User
Tags abs

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:

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.