本文实例为大家分享了python绘制雪花的具体代码,供大家参考,具体内容如下
代码非常容易理解,画着玩玩还是可以的。直接上代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# -*- coding: utf-8 -*- """ Created on Fri Jan 12 14:35:14 2018 @author: Administrator """ 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() |
运行结果
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/qq_40006058/article/details/79044193