python使用turtle库与random库绘制雪花
本文实例为大家分享了python绘制雪花的具体代码,供大家参考,具体内容如下
代码非常容易理解,画着玩玩还是可以的。直接上代码
# -*- coding: utf-8 -*- """ Created on Fri Jan 12 14:35:14 2018 @author: Administrator """ 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()
运行结果
相关推荐
xiaouncle 2020-07-31
guangyacyb 2020-06-14
pengkunstone 2020-06-09
jessieHJ 2020-05-31
Lexan 2020-04-15
wangqing 2020-04-07
xclxcl 2020-03-04
新路 2020-02-26
明天你好 2020-01-28
大脸猫脸大 2020-01-18
georgeandgeorge 2019-12-28
doubinning 2019-12-05
singer 2019-12-04
那年夏天 2019-11-17
xinhao 2019-11-12
jocleyn 2019-11-10
zhinanpolang 2019-08-23
prettyice 2010-03-24