python day 4 turtle

 

 

Turtle

  1. turtle library is python standard library ( Library one), that is mounted directly to the interpreter along with the operating system function modules.
  2. Turtle canvas pixel is the smallest unit of space,
  3. Turtle drawing form

Turtle.setup(widthheightstartxstarty)

The latter two parameters is optional, the default is the form in the center of the screen

Setup () does not have to automatically generate normal form

Upper left corner of the screen coordinates ( 0,0 )

Form the upper left corner of the form coordinate origin

  1. Absolute coordinates: the origin of the coordinate plane rectangular coordinate system in the center of the form, the

Turtle.goto (x, y) regardless of where the turtles go straight to the coordinate

   Turtles coordinates: the position of sea turtles are currently located the origin of coordinates, direction of the head as forward direction

  1. The absolute angle: for the use of angular units

The forward direction is 0 degrees, clockwise rotation, i.e., the left side is 90 degrees, the right side is 270 degrees or -90 degrees

Turtle.seth (angle) to change the turtle forward for absolute certain angle

Note: This function only changes the direction of, but not make it proceeds

Seth is set heading abbreviations i.e., the forward direction is provided

Under the turtle coordinate system point of view:

Turtle.left(angle)

Turtle.right(angle)

  1. RGB color system

Turtle default to decimal expression can be switched

Turtle.colormode(mode)

  1. Library reference and import

(1) import turtle   function expression: library name . Function name ( parameter )

Cons: long function name

(2) From turtle import * function expression: function name ( parameter )

Disadvantages: easy to duplicate names

(3) Import turtle as tur function expression: library name . Function name ( parameter )

Improved: the name of the library to the other from a short name

  1. Brush Control Functions

Turtle.penup () Turtles took off, leaving no footprints

Turtle.pendown ()   turtle landing, continue drawing

Turtle.pensize () is equivalent to the waist turtles

Turtle.color () turtles footprint color parameter may be the RGB , or may be a string type of color, e.g. turtle.color ( 'Purple') turtle.color (0.5,0.5,0.5)

All control functions are long-term, rather than one-off, that is, before the next change will remain in effect

  1. Motion control function

Turtle.circle (r, angle) r is the radius, center left defaults to the current distance of turtle r position

   Range is the angle of the drawing, i.e., drawing a central angle range of circular arc

If the range is not selected, the default whole round draw

Turtle.fd () Control turtles straight line, the parameter can be positive or negative

  1. Turtle in the loop

For variable in range ( number ):

Expression

Variable represents each cycle of the count, a reduced number of executions

  1. Turtle.done () does not automatically close the form, manually close

 

Guess you like

Origin www.cnblogs.com/cfqlovem-521/p/11815613.html