「青少年编程竞赛交流群」已成立(适合6至18周岁的青少年),公众号后台回复【Scratch】或【Python】,即可进入。如果加入了之前的社群不需要重复加入。
案例:绘制兔子时钟
代码
import turtlet = turtle.Pen()# 表盘
t.pensize(2)
t.fillcolor("pink")
t.begin_fill()
t.penup()
t.goto(0, -100)
t.pendown()
t.circle(100)
t.end_fill()# 时针、分针、秒针
t.penup()
t.goto(0, 0)
t.pendown()
t.forward(40)
t.back(40)
t.left(90)
t.forward(63)
t.back(63)
t.left(110)
t.forward(80)
t.back(80)# 表盘刻度
t.penup()
t.goto(30, 80)
t.pendown()
t.right(40)
for i in range(12):t.write(i + 1, t.pencolor("dodgerblue"))t.penup()t.circle(90, -30)t.pendown()# 外侧耳朵
t.pencolor("black")
t.fillcolor("pink")
t.penup()
t.goto(-30, 95)
t.setheading(90)
t.pendown()t.begin_fill()
t.forward(40)
t.circle(20, 180)
t.forward(65)
t.end_fill()t.penup()
t.goto(30, 95)
t.setheading(90)
t.pendown()t.begin_fill()
t.forward(40)
t.circle(-20, 180)
t.forward(65)
t.end_fill()# 内侧耳朵
t.pencolor("white")
t.fillcolor("white")
t.penup()
t.goto(-40, 100)
t.setheading(90)
t.pendown()t.begin_fill()
t.forward(35)
t.circle(10, 180)
t.forward(35)
t.end_fill()t.penup()
t.goto(40, 100)
t.setheading(90)
t.pendown()t.begin_fill()
t.forward(35)
t.circle(-10, 180)
t.forward(35)
t.end_fill()turtle.done()
视频讲解
000