还是回到turtle吧。
先上官方示例
from turtle import *
color('red', 'yellow')
begin_fill()
while True:
forward(200)
left(170)
if abs(pos()) < 1:
break
end_fill()
done()
Turtle motion
Move and draw
forward() | fd() #前移
backward() | bk() | back() #后移
right() | rt() #向右
left() | lt() #向左
goto() | setpos() | setposition() #定位
setx() #x方向(水平)定位
sety() #y方向(竖直)定位
setheading() | seth() #朝向
home() #复位(0,0)
circle() #圆
dot() #点
stamp() #复制当前
clearstamp() #
clearstamps() #
undo() #撤销操作
speed() #速度控制
>>> import turtle
>>> t = turtle.Pen()
>>> t.position()
(0.00,0.00)
>>> t.forward(25)
>>> t.position()
(25.00,0.00)
>>> t.forward(-75)
>>> t.position()
(-50.00,0.00)
>>> t.backward(30)
>>> t.position()
(-80.00,0.00)
>>> t.heading()
0.0 #默认向右为0,逆时针为正,顺时针为负
>>> t.right(45)
>>> t.heading()
315.0
>>> t.left(45)
>>> t.heading()
0.0
>>> t.pos()
(0.00,0.00)
>>> t.setpos(60,30)
>>> t.pos()
(60.00,30.00)
>>> t.setpos(20,80)
>>> t.pos()
(20.00,80.00)
>>> t.pos()
(20.00,80.00)
>>> t.setx(10)
>>> t.pos()
(10.00,80.00)
>>> t.setx(-10)
>>> t.pos()
(-10.00,80.00)
>>> t.sety(100)
>>> t.pos()
(-10.00,100.00)
>>> t.heading()
0.0 #方向为E
>>> t.setheading(90)
>>> t.heading()
90.0 #方向为N
>>> t.pos()
(-10.00,100.00)
>>> t.home()
>>> t.pos()
(0.00,0.00)
今天先到这吧,明天继续……
ok,继续吧
>>> t.pos()
(0.00,0.00)
>>> t.heading()
0.0
>>> t.circle(50)
>>> t.heading()
0.0
>>> t.pos()
(-0.00,0.00)
>>> t.circle(120, 180)
>>> t.heading()
180.0
>>> t.pos()
(0.00,240.00)
>>> t.dot()
>>> t.fd(50); t.dot(20, "blue"); t.fd(50)
>>> t.pos()
(100.00,0.00)
>>> t.heading()
0.0
>>> t.color("blue")
>>> t.stamp()
10
>>> t.fd(50)
>>> t.pos()
(150.00,0.00)
>>> t.color("red")
>>> ts = t.stamp()
>>> t.fd(50)
>>> t.pos()
(200.00,0.00)
>>> t.clearstamp(ts)
>>> t.pos()
(200.00,0.00)
>>> for i in range(8):
t.stamp(); t.fd(10)
24
25
26
27
28
29
30
31
>>> t.clearstamps(2)
>>> t.clearstamps(-2)
>>> t.clearstamps()
>>> t.reset()
>>> for i in range(4):
t.fd(50); t.lt(90)
>>> for i in range(8):
t.undo()
>>> t.speed()
3
>>> t.speed('normal')
>>> t.speed()
6
>>> t.speed(9)
>>> t.speed()
9