- The overview of Turtle Library
Turtle Library is a python implementation of the Turtle Mapping System.(from 1969, for programming design)
Turtle LIbrary is a standard library from python language.(Standard library:the functional module in the operating system directly installed by the interpreter)
Library, Package, Module have some different.
Absolute Coordinate System: the central of the screen is the zero-point of this coordinate system, others are same as the Mathematical Coordinate System. this system include the Absolute Angle System, which is also same as Angle System of the Mathematical Coordiante System.
Turtle Coordinate System: the direction the turtle moves called “forward”, the left and the right direction is turtle’s left and right. The function "turtle.circle(rad, angle)"means that the curve is run with a point which is in the left of the turtle’s current position as the center of the circle, parameters “rad” means radius and "angle"means the rotation angle. It also has a Turtle Angle System which is based on turtle’s direction.
turtle.setup(width, height, startx, starty):Used to sitting the size and position of the window.
It has 4 parameters and the later two are alternated.
The parameters “width” and “height” means the width and the height of the window.
The parameters “startx” and “starty” determined the position of the top-left-corner of the window.
Setup Function is not necessary, only if you want control the size of window.
turtle.goto(x, y):Used to let the turtle go to the target-point.
The position of the target-point are determined by the parameters “x” and “y”.
turtle.seth(angle) [In Absolute Angle System]:Used to change the direction of the turtle, this function only changes the direction but does NOT move.
The parameter “angle” is absolute angle.
turtle.left(angle) / turtle.right(angle) [In Turtle Angle System]:Used to change the direction of the turtle, based on Turtle Angle System.
The parameter “angle” is turtle’s angle, beyond the turtle is positive angle, below is negative.*
- RGB Color System
common RGB color
EnName | RGB | RGB in Decimal |
---|---|---|
white | 255, 255, 255 | [1, 1, 1] |
yellow | 255, 255, 0 | [1, 1, 0] |
magenta | 255, 0, 255 | [1, 0, 1] |
cyan | 0, 255, 255 | [0, 1, 1] |
blue | 0, 0, 255 | [0, 0, 1] |
black | 0, 0, 0 | [0, 0, 0] |
seashell | 255, 245, 238 | [1, 0.96, 0,93] |
gold | 255, 215, 0 | [1, 0.84, 0] |
pink | 255, 192, 203 | [1, 0.75, 0.80] |
brown | 165, 42, 42 | [0.65, 0.16, 0.16] |
purple | 160, 32, 240 | [0.63, 0.13, 0.94] |
tomato | 255, 99, 71 | [1, 0.39, 0.28] |
turtle.colormode(mode)Two options:
1.0: RGB small numerical
255: RGB integer
- The reference of Turtle Base and “import”
Using the key word “import” to cite the Turtle base.
There are four Pen Control Functions in Python language:
penup(): Used to apprent with pendown(), when the Penup Function is operating, the track of turtle will not show on the screen.
pendown(): Has the opposite function with the Penup Function, when the Pendown Function is operating, the track of turtle will show on the screen.
pensize(width): AKA turtle.width(width), used to setup the size of pen.
pencolor(color): give the pen color, using Color String, RGB Decimal Value or RGB Array to assign the parameter “color”.
There are two Mobile Control Functions:
forward(d): AKA turtle.fd(d), make the turtle go straight, the parameter “d” is distance of the turtle move, when its value is under zero, means backward.
circle(r, extent): Draw the arc of the “extent” angle according to the radium “r”. The default central of the circle is on the left of the turtle.
There is a Direction Control Function:
setheading(angle): AKA turtle.seth(angle): to change the direction of the turtle, makes turtle go at an angle.[In Absolute Coordinate System]
Loop Statement and function range(num):
for in is a couple of key words, in For i In range(num) statement, executive the statement from i to num-1, when i wasn’t assigned, the default value is zero.
Using turtle.done() to hang out the window.