用Python绘制布朗熊:Turtle库实现的创意编程 | 南锋

南锋

南奔万里空,脱死锋镝余

用Python绘制布朗熊:Turtle库实现的创意编程

无意间在抖音发了一个用python画布朗熊的视频,没想到想要代码的人还挺多,现在就把代码发布在这里,需要的朋友自取。

特别注意: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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from turtle import *
ht()
setup(400,800,0,0)
seth(0)
pensize(3)
pencolor("black")
pu() #penup()
goto(0,100)
pd() #pendown()
fillcolor("brown")
begin_fill()
circle(100)
end_fill()
pu()
goto(0,150)
pd()
fillcolor("white")
begin_fill()
pencolor("white")
circle(30)
end_fill()
pencolor("black")
pu()
goto(0,179)
lt(45)
fd(35)
rt(45)
pd()
fillcolor("black")
begin_fill()
circle(10)
end_fill()
pu()
goto(0,179)
lt(135)
fd(35)
rt(135)
pd()
fillcolor("black")
begin_fill()
circle(10)
end_fill()
pu()
goto(0,180)
pd()
fillcolor("black")
begin_fill()
circle(6)
end_fill()
goto(-3,180)
seth(-135)
pensize(5)
fd(12)
pu()
goto(3,180)
pd()
seth(-45)
pensize(5)
fd(12)
pensize(3)
pu()
goto(0,200)
seth(30)
fd(100)
pd()
fillcolor("brown")
begin_fill()
circle(30,215)
end_fill()
pu()
goto(0,200)
seth(150)
fd(100)
pd()
fillcolor("brown")
begin_fill()
circle(-30,215)
end_fill()
pu()
goto(50*pow(3,0.5),152) #pow(x,y)=x**y
seth(60)
pd()
fillcolor("brown")
begin_fill()
circle(-15,180)
circle(-130,30)
seth(-90)
circle(-1000,8)
for i in range(2):
seth(-90)
circle(-27,180)
lt(10)
circle(-1000,8)
seth(150)
circle(-130,30)
circle(-16,180)
circle(100,120)
end_fill()
pu()
goto(0,80)
seth(0)
pd()
pencolor("black")
fillcolor("black")
begin_fill()
circle(-40)
end_fill()
done()
+