forked from jackzhenguo/python-small-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathturtlesnow.py
More file actions
30 lines (26 loc) · 805 Bytes
/
turtlesnow.py
File metadata and controls
30 lines (26 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import turtle as p
import random
def snow(snow_count):
p.hideturtle()
p.speed(500)
p.pensize(2)
for i in range(snow_count):
r = random.random()
g = random.random()
b = random.random()
p.pencolor(r, g, b)
p.pu()
p.goto(random.randint(-350, 350), random.randint(1, 270))
p.pd()
dens = random.randint(8, 12)
snowsize = random.randint(10, 14)
for _ in range(dens):
p.forward(snowsize) # 向当前画笔方向移动snowsize像素长度
p.backward(snowsize) # 向当前画笔相反方向移动snowsize像素长度
p.right(360 / dens) # 顺时针移动360 / dens度
def main():
p.setup(800, 600, 0, 0)
p.bgcolor("black")
snow(30)
p.mainloop()
main()