有几十个雪花状的图案在旋转,但是只有一个海龟对象。这是由于所有的雪花都是画出来的。
下面是部分代码预览:
"""
旋转雪花单线程画笔版.py
"""
from turtle import *
def draw_snow(t,snow):
"""画雪花"""
t.color(snow.color)
t.goto(snow.pos)
t.setheading(snow.angle)
t.pendown()
for _ in range(8):
t.fd(snow.length)
t.bk(snow.length)
t.rt(45)
t.penup()
class Snow:
"""雪花类"""
def __init__(self,length,pos,color):
pass
color_list = ('red','orange','yellow','green',
'cyan','blue','purple','pink')
width,height = 720,640
screen = Screen()
screen.tracer(0,0)
screen.bgcolor('black')
screen.setup(width,height)
screen.title("旋转雪花单线程画笔版")
i = 0
snows = [] # 定义雪花表
for x in range(100-width//2,width//2,100):
for y in range(100-height//2,height//2,100):
color = color_list[i]
i = i + 1
i = i % len(color_list)
snows.append(Snow(20,(x,y),color))
t = Turtle(visible=False) # 画画的龟
t.penup()
如需要查看完整源代码,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)

