import turtle as t
t.setup(650,350,200,200) #建立绘图窗口
t.penup() # 画笔提起
t.fd(-250) #前进 -250 个像素
t.pendown() #落笔
t.pensize(25)
t.pencolor("purple")
t.seth(-40) # 海龟方向为 X轴顺时针转 40度
for i in range(4):
t.circle(40,80)
t.circle(-40,80)
t.circle(40,80/2)
t.fd(40)
t.circle(16,180)
t.fd(49*2/3) # 如果加上 # t.hideturtle() 可以隐藏海龟
t.done()
结果:
.------------------------------------------------------------------------------------------------------------------
分析:
import turtle as t
引入一个名字叫 turtle的绘图库 并将其取一个小名为:t (目的方便下面代码的书写并与其他函数加以区分),最小单位:像素
t.penup() # 画笔提起
t.pendown() #落笔
penup() 的别名: up() 、pu()
pendown()的别名 :pd()
penup() 让海龟在窗口中不留痕迹的移动,pendown()让海龟在绘图窗口里作画留痕
(本人脑子笨一开始不理解,不过想象成上个世纪的黑胶唱片就能更好理解了)
唱针放下发出声音,提起无音。
t.circle(40,80/2)
turtle.circle(r, angle) 以海龟正左侧距离r像素的位置为圆心曲线运动 angle 的角度
(如果需要向右侧运动则 t.circle(-40,80/2) , 其中的 80/2 可以写为 40. 这里写成80/2 是为了更好地帮助阅读者理解与之前 t.circle(40,80) 海龟的运动角度。)
拓展
海龟的方向控制:
t.setheahing(angle) 别名 t.seth() # 以X轴为0度,逆时针旋转angle 角度
t.left(angle) # 海龟的当前方向左转angle角度
t.right(angle) #海龟的当前方向右转angle角度