** turtle模块和random模块

 turtle模块和random模块

 1 # -*- coding: utf-8 -*-
 2 # ~ import turtle
 3 # ~ import random
 4 from turtle import *
 5 from random import *
 6 def ground():
 7     hideturtle()
 8     speed(100)
 9     for i in range(400):
10         pensize(randint(5,10))
11         x=randint(-400,350)
12         y=randint(-280,-1)
13         r=-y/280
14         g=-y/280
15         b=-y/280
16         pencolor(r,g,b)
17         penup()
18         goto(x,y)
19         pendown()
20         forward(randint(40,100))
21 def snow():
22     hideturtle()
23     speed(100)
24     pensize(2)
25     for i in range(100):
26         r=random()
27         g=random()
28         b=random()
29         pencolor(r,g,b)
30         penup()
31         setx(randint(-350,350))
32         sety(randint(1,270))
33         pendown()
34         dens=randint(8,12)
35         snowsize=randint(10,14)
36         for j in range(dens):
37             forward(snowsize)
38             backward(snowsize)
39             right(360/dens)
40 def main():
41     setup(800, 600, 0, 0)
42     tracer(False)
43     bgcolor("black")
44     snow()
45     ground()
46     tracer(True)
47     mainloop()
48 main()

 

 

 

posted @ 2019-03-08 20:32  王琳杰  阅读(441)  评论(0编辑  收藏  举报