用python画圣诞树

turtle 还挺好玩的啊😎

用 python 的 turtle 库画圣诞树🎄


代码部分

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from turtle import *
import random
import time

n = 80.0

speed("fastest")
screensize(bg='seashell')
time.sleep(7)
left(90)
forward(3*n)
color("orange", "red")
begin_fill()

left(126)

for i in range(5):
forward(n/5)
right(144)
forward(n/5)
left(72)
'''
right(90)
forward(n/6)
left(120)
forward(n/3)
left(120)
forward(n/3)
left(120)
forward(n/6)
'''
end_fill()
#left(90)
right(126)

color("dark green")
backward(n*4.8)
def tree(d, s):
if d <= 0: return
forward(s)
tree(d-1, s*.8)
right(120)
tree(d-3, s*.5)
right(120)
tree(d-3, s*.5)
right(120)
backward(s)
tree(15, n)
backward(n/2)

for i in range(200):
a = 200 - 400 * random.random()
b = 10 - 20 * random.random()
up()
forward(b)
left(90)
forward(a)
down()
if random.randint(0, 1) == 0:
color('tomato')
else:
color('wheat')
circle(2)
up()
backward(a)
right(90)
backward(b)

time.sleep(5)
------本文结束感谢您的阅读 ------
0%