环境准备
运行平台: Windows
Python版本: Python 3.6.4
IDE: Pycharm或自带的IDLE
如果你感觉学不会?莫慌,小编推荐大家加入群,
前面548中间377后面875,群里有志同道合的小伙伴,
互帮互助,还可以拿到许多视频教程!
绘制代码
from turtle import *
from random import *
def ground():
hideturtle()
speed(100)
for i in range(400):
pensize(randint(5,10))
x=randint(-400,350)
y=randint(-280,-1)
r=-y/280
g=-y/280
b=-y/280
pencolor(r,g,b)
penup()
goto(x,y)
pendown()
forward(randint(40,100))
def snow():
hideturtle()
speed(100)
pensize(2)
for i in range(100):
r=random()
g=random()
b=random()
pencolor(r,g,b)
penup()
setx(randint(-350,350))
sety(randint(1,270))
pendown()
dens=randint(8,12)
snowsize=randint(10,14)
for j in range(dens):
forward(snowsize)
backward(snowsize)
right(360/dens)
def main():
setup(800, 600, 0, 0)
tracer(False)
bgcolor("black")
snow()
ground()
tracer(True)
mainloop()
main()
运行结果:
领取专属 10元无门槛券
私享最新 技术干货