python绘制雪景图-创新互联
本文实例为大家分享了python绘制雪景图的具体代码,供大家参考,具体内容如下
成都服务器托管,成都创新互联提供包括服务器租用、绵阳服务器托管、带宽租用、云主机、机柜租用、主机租用托管、CDN网站加速、域名注册等业务的一体化完整服务。电话咨询:18980820575绘制雪景图,应用到turtle和random。
from turtle import * from random import * # 绘制随机雪花 def DrawSnow(snow): x = randrange(-750, 750) y = randrange(-50, 400) snowcolor = (randrange(0, 255), randrange(0, 255), randrange(0, 255)) snowsize = randrange(10, 20) snowstyle = choice([30, 45]) snow.penup() snow.setpos(x, y) snow.pendown() colormode(255) snow.pencolor(snowcolor) for i in range(int(360/snowstyle)): if snowsize < 11: snowstyle = 90 snow.forward(snowsize) snow.backward(snowsize) snow.right(snowstyle) #绘制上半部分雪花 def InitSnow(n): snow = Turtle() for i in range(n): DrawSnow(snow) #绘制下半部分雪地 def InitField(): field = Turtle() colormode(255) for i in range(300): x = randrange(-850, 850) y = randrange(-400, 0) width = randrange(50, 200) length = randrange(3, 8) field.penup() field.setpos(x, y) field.pendown() tempcolor = int(-255 * y/400) print(tempcolor) fieldcolor = (tempcolor, tempcolor, tempcolor) field.color(fieldcolor, fieldcolor) field.begin_fill() field.fd(width) field.circle(length, 180) field.fd(width) field.circle(length, 180) field.end_fill() def main(): bgcolor("black") tracer(False) InitField() InitSnow(200) tracer(True) mainloop() if __name__ == '__main__': main()
文章标题:python绘制雪景图-创新互联
网站URL:http://ybzwz.com/article/dpicdi.html