一复习turtle() 库中的函数
前进 forward()、
旋转 left() 和 right() 、
画圆 circle() 、
设置速度speed() 、
画点 dot()
设置变量: Pen()
二学习新知
penup() 抬笔
pendown() 落笔
三绘制宝珠。参考答案:
import turtle
#海龟双子星之宝珠
Star1= turtle.Pen()
Star2= turtle.Pen()
Star1.speed(50)
Star2.speed(50)
Star1.pensize(3)
Star2.pensize(3)
Star1.left(90)
Star2.up()
Star2.backward(100)
Star2.pendown()
Star2.rigt(90)
Star1.circle(50)
Turtle.done
For _count in range(100):
Star1.forward(1)
Star2.forward(1)
Star1.left(2)
Star2.left(2)
#花纹
For _count in range(100):
Star1.forward(1)
Star2.forward(1)
Star1.left(3)
Star2.left(3)
#更精致的花纹
For _count in range(50):
Star1.forward(1)
Star2.forward(1)
Star1.left(5)
Star2.left(5)
turtle.done()
四挑战:
1旋转太极图:代码参考答案
import turtle
a = turtle.Pen()
t = turtle.Pen()
a.speed(100)
t.speed(100)
t.pencolor("#ffffff")
t.right(180)
for __count in range(2):
for __count in range(180):
t.circle(50)
t.left(1)
a.circle(50)
a.left(1)
turtle.done()
2. Triple——回旋镖:代码参考答案
import turtle
#召唤画笔海龟t、a、b
t = turtle.Pen()
a = turtle.Pen()
b = turtle.Pen()
t.left(90)
a.right(30)
b.right(150)
t.forward(50)
#海龟a和b前进50步
a.forward(50)
b.forward(50)
t.dot(100)
#海龟a和b分别画点
a.dot(100)
b.dot(100)
t.pencolor("#ffffff")
a.pencolor("#ffffff")
b.pencolor("#ffffff")
t.right(90)
#海龟a和b向右旋转90°
a.right(90)
b.right(90)
t.forward(20)
a.forward(20)
b.forward(20)
t.dot(70)
a.dot(70)
b.dot(70)
turtle.done()