Commit eeb5969a by BellCodeEditor

save project

parent 5bd73894
Showing with 23 additions and 13 deletions
import turtle import turtle
radius = 80 import random
turtle.color("red", "pink") # 设置画笔颜色和填充色 width = 800 # 窗体宽度
turtle.pensize(2) # 设置画笔大小 height = 600 # 窗体高度
turtle.begin_fill() # 开始填充 num = 100 # 雪花数
turtle.left(45) # 左转45度 turtle.setup(width, height) # 窗口大小宽度800像素,高度600像素
turtle.fd(2 * radius) # 前进 turtle.tracer(False) # 关闭动画,显示结果更快
turtle.circle(radius, 180) # 画半圆 turtle.bgcolor("black") # 设置背景颜色为黑色
turtle.right(90) # 右转90度
turtle.circle(radius, 180) # 画半圆
turtle.fd(2 * radius) # 前进200像素
turtle.end_fill() # 结束填充
turtle.hideturtle() # 隐藏指针 turtle.hideturtle() # 隐藏指针
turtle.done() # 结束,停留在当前界面 turtle.pensize(2) # 设置画笔大小
\ No newline at end of file for i in range(num): # 循环绘制每一个雪花
r, g, b = random.random(), random.random(), random.random() # 随机生成颜色
turtle.pencolor(r, g, b) # 设置画笔颜色
turtle.penup() # 提起画笔,需要移动位置
turtle.setx(random.randint(-width // 2, width // 2)) # 设置 x 坐标位置
turtle.sety(random.randint(-height // 2, height // 2)) # 设置 y 坐标位置
turtle.pendown() # 按下画笔,准备绘画
lines = random.randint(6, 12) # 随机生成雪花的线条数
snow_size = random.randint(8, 16) # 随机生成线条的长度
for j in range(lines): # 循环画线条
turtle.forward(snow_size) # 画线条
turtle.backward(snow_size) # 回到原位置
turtle.right(360 / lines) # 改变角度,线条均匀分开
turtle.done() # 绘画完成,停留在当前页面
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment