Python learning about Turtle
Turtle learning
Graphics base:turtle
Main usage:painting
Some tips:
- use dir(third base) can get all function in third base
- use help(third base) can get the introduction to third base
- use help(third base.function)can get the use of function
For example:
- dir(turtle)
- help(turtle)
- help(turtle.back)
Practice project:one pig who name is peiqi
Turtle Function
-
pensize(1-10) : the pen size
-
hideturtle(): hide the pen
-
colormode(1 or 255) : select mode of color divide 1 or 255 in r,g,b the three basic color
-
color(‘type’ or ‘number-r,g,b’) : which can use two style and can mix with two color
-
setup(width = ,height = ,startx = ,starty = ) : set canvas size and the pen where to start
-
speed(0-10) : from 1 to 10 begin very fast and 0 is the fastest
-
penup() | pu | up : all represent no drawing when pen start to move
-
pendown() | pd | down : all represent put the pen down in canvas
-
setpos(x,y) | setpostion | goto : get the pen to specific location x and y both are number
-
setheading(angle) | seth : to adjust the angle of pen
-
begin_fill() | end_fill : fill the color in painting
-
left(angle) | lf : left some angle while painting
-
forward(number) | fd : move pen forward some distance
-
circle(r,angle,step) : to painting circle ‘r’ is radius ‘angle’ is circle length ‘step’ is calculate numbers
Turtle steps
first:set pensize | canvas size | speed | colormode before color
second: penup | pendown | setpostion
third: setheading | left | forward | circle | begin_fill | begin_end
four: mainloop
Turtle practice
import turtle as tu
#first
tu.pensize(4)
tu.setup(800,600,400,200)
tu.speed(5)
tu.colormode(255)
tu.color(205,65,160)
#second
tu.penup()
tu.setpos(20,50)
tu.pendown()
tu.begin_fill()
tu.goto(60,30)
#third
tu.setheading(90)
tu.forward(100)
tu.left(90)
tu.forward(100)
tu.end_fill()
tu.circle(20,180,5)
#four
tu.mainloop()