python turtle 画图

关键的几个代码:

Turtle motion

Move and draw

forward() | fd()
backward() | bk() | back()
right() | rt()
left() | lt()
goto() | setpos() | setposition()
setx()
sety()
setheading() | seth()
home()
circle()
dot()
stamp()
clearstamp()
clearstamps()
undo()
speed()

Tell Turtle’s state

position() | pos()
towards()
xcor()
ycor()
heading()
distance()
Setting and measurement
degrees()
radians()

Pen control

Drawing state

pendown() | pd() | down()
penup() | pu() | up()
pensize() | width()
pen()
isdown()

Color control

color()
pencolor()
fillcolor()
Filling
fill()
begin_fill()
end_fill()
example:画个苹果

import turtle
turtle.pendown()
turtle.fillcolor("red")
turtle.begin_fill()
turtle.circle(60, 360)
turtle.end_fill()
turtle.circle(60,180)
turtle.left(90)
turtle.forward(20)
turtle.left(90)
turtle.forward(10)
turtle.back(20)
turtle.forward(10)
turtle.left(90)
turtle.forward(50)
turtle.back(20)
turtle.left(180)
turtle.penup()
turtle.circle(60, 270)
turtle.pendown()
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(60, 90)
turtle.left(90)
turtle.circle(60, 90)
turtle.left(135)
turtle.fd(90)
turtle.end_fill()
turtle.done()

你可能感兴趣的:(python,turtle)