用Python画雪景图
程序员文章站
2024-01-16 15:41:17
新年来临之际,用Python画了一幅雪景图,祝大家新年快乐,瑞雪兆丰年。 说明:以下代码是从Python教程中学习来的。#SnowView.pyfrom turtle import *from random import *def drawSnow(): hideturtle() pensize(2) for i in range(100): r,g,b=random(),random(),random(......
新年来临之际,用Python画了一幅雪景图,祝大家新年快乐,瑞雪兆丰年。
说明:以下代码是从Python教程中学习来的。
#SnowView.py
from turtle import *
from random import *
def drawSnow():
hideturtle()
pensize(2)
for i in range(100):
r,g,b=random(),random(),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 drawGround():
hideturtle()
for i in range(400):
pensize(randint(5,10))
x=randint(-400,350)
y=randint(-280,-1)
r,g,b=-y/280,-y/280,-y/280
pencolor((r,g,b))
penup()
goto(x,y)
pendown()
forward(randint(0,100))
setup(800,600,200,200)
tracer(False)
bgcolor("black")
drawSnow()
drawGround()
done()
本文地址:https://blog.csdn.net/weixin_51630390/article/details/112055487
推荐阅读