一年一度的元宵节刚刚过去,由于时间关系,在元宵节当天晚上11点多才完成本文灯笼的绘制。这两天又在忙着别的事情,所以现在才跟大家分享。
一、效果展示
在介绍代码之前,先来看下本文的实现效果。
二、代码展示
接下来展示绘制灯笼的全量源代码
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
import os import pygame import turtle as t ##画外轮廓 t.title( '元宵节字谜灯笼' ) t.setup(startx = 0 , starty = 0 ) #画灯笼提线 t.penup() t.goto( - 50 , 180 ) t.pendown() t.left( 100 ) t.pensize( 2 ) t.color( 'orangered' ) t.circle( - 15 , 80 ) t.right( 140 ) t.forward( 20 ) #画灯笼盖 t.penup() t.goto( - 57 , 179 ) t.pendown() t.left( 120 ) t.pensize( 1 ) #t.pencolor('gold') t.pencolor( '#fedf08' ) t.fillcolor( '#fedf08' ) #t.pencolor('orange') t.begin_fill() t.forward( 14 ) t.right( 15 ) t.forward( 20 ) t.right( 165 ) t.forward( 52 ) t.goto( - 57 , 179 ) t.end_fill() t.penup() t.goto( - 78 , 174 ) t.pendown() t.left( 135 ) t.pencolor( '#feb209' ) t.fillcolor( '#feb209' ) t.begin_fill() t.forward( 5 ) t.left( 45 ) t.forward( 47 ) t.goto( - 22 , 174 ) t.end_fill() #红色的柱子 t.penup() t.goto( - 70 , 170 ) t.pendown() t.color( 'red' ) t.begin_fill() t.right( 90 ) t.forward( 10 ) t.left( 90 ) t.forward( 40 ) t.left( 90 ) t.forward( 10 ) t.end_fill() def zz(x): t.penup() t.color( '#feb209' ) t.pensize( 1 ) t.begin_fill() t.goto(x, 160 ) t.forward( 10 ) t.right( 90 ) t.forward( 3 ) t.right( 90 ) t.forward( 10 ) t.right( 90 ) t.forward( 3 ) t.end_fill() t.right( 90 ) zz( - 64 ) #第一根柱子 zz( - 55 ) #第二根柱子 zz( - 45 ) #第三根柱子 zz( - 37 ) #第四根柱子 #棕色的柱子 t.penup() t.goto( - 74 , 160 ) t.pendown() t.color( '#7f4e1e' ) t.left( 90 ) t.begin_fill() t.circle( 2 , 90 ) t.forward( 5 ) t.left( 90 ) t.forward( 52 ) t.left( 90 ) t.forward( 5 ) t.circle( 2 , 90 ) t.forward( 50 ) t.end_fill() #灯笼外壳 t.penup() t.goto( - 76 , 153 ) t.pendown() t.begin_fill() t.color( 'orangered' ) t.circle( 30 , 90 ) t.forward( 70 ) t.circle( 30 , 90 ) t.forward( 52 ) t.circle( 30 , 90 ) t.forward( 70 ) t.circle( 30 , 90 ) t.end_fill() #棕色的柱子 t.penup() t.goto( - 74 , 23 ) t.pendown() t.color( '#7f4e1e' ) #t.left(90) t.begin_fill() t.circle( 2 , 90 ) t.forward( 5 ) t.left( 90 ) t.forward( 52 ) t.left( 90 ) t.forward( 5 ) t.circle( 2 , 90 ) t.forward( 50 ) t.end_fill() #黄色的线 t.penup() t.goto( - 50 , 15 ) t.pendown() t.left( 90 ) t.color( 'yellow' ) t.pensize( 1 ) t.forward( 25 ) #玫红色的球 t.right( 90 ) t.color( 'red' ) t.begin_fill() t.circle( 8 , 360 ) t.end_fill() #画流苏 t.penup() t.goto( - 50 , - 26 ) t.pendown() t.begin_fill() t.color( 'orangered' ) t.circle( 9 , 90 ) t.forward( 80 ) t.left( 90 ) t.forward( 18 ) t.left( 90 ) t.forward( 80 ) t.circle( 9 , 90 ) t.end_fill() #画流苏中黄色的圈 t.penup() t.goto( - 59 , - 42 ) t.left( 90 ) t.pendown() t.begin_fill() t.color( '#fedf08' ) t.forward( 10 ) t.left( 90 ) t.forward( 18 ) t.left( 90 ) t.forward( 10 ) t.left( 90 ) t.forward( 18 ) t.end_fill() #中文 t.hideturtle() t.penup() t.goto( - 72 , 120 ) t.pendown() t.pencolor( 'black' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '猜灯谜' , font = ( 'Comic Sans' , 11 , 'normal' )) t.penup() t.goto( - 87 , 91 ) t.pendown() t.pencolor( 'black' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '云 盖 中 秋 月' , font = ( 'Times New Roman' , 10 , 'normal' )) t.penup() t.goto( - 87 , 65 ) t.pendown() t.pencolor( 'black' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '雨 淋 元 宵 灯' , font = ( 'Times New Roman' , 10 , 'normal' )) t.penup() t.goto( - 84 , 40 ) t.pendown() t.pencolor( 'black' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '(打 一 成 语)' , font = ( 'Times New Roman' , 10 , 'normal' )) t.delay( 50 ) def write_1(): #元 t.penup() t.goto( 90 , 150 ) t.pendown() t.pensize( 8 ) t.pencolor( 'red' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '共' , font = ( 'Times New Roman' , 18 , 'normal' )) #宵 t.penup() t.goto( 90 , 120 ) t.pendown() t.pensize( 8 ) t.pencolor( 'red' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '饮' , font = ( 'Times New Roman' , 18 , 'normal' )) #节 t.penup() t.goto( 90 , 90 ) t.pendown() t.pensize( 8 ) t.pencolor( 'red' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '太' , font = ( 'Times New Roman' , 18 , 'normal' )) #快 t.penup() t.goto( 90 , 60 ) t.pendown() t.pensize( 8 ) t.pencolor( 'red' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '平' , font = ( 'Times New Roman' , 18 , 'normal' )) #乐 t.penup() t.goto( 90 , 30 ) t.pendown() t.pensize( 8 ) t.pencolor( 'red' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '酒' , font = ( 'Times New Roman' , 18 , 'normal' )) def write_2(): #元 t.penup() t.goto( 150 , 150 ) t.pendown() t.pensize( 8 ) t.pencolor( 'red' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '同' , font = ( 'Times New Roman' , 18 , 'normal' )) #宵 t.penup() t.goto( 150 , 120 ) t.pendown() t.pensize( 8 ) t.pencolor( 'red' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '猜' , font = ( 'Times New Roman' , 18 , 'normal' )) #节 t.penup() t.goto( 150 , 90 ) t.pendown() t.pensize( 8 ) t.pencolor( 'red' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '元' , font = ( 'Times New Roman' , 18 , 'normal' )) #快 t.penup() t.goto( 150 , 60 ) t.pendown() t.pensize( 8 ) t.pencolor( 'red' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '宵' , font = ( 'Times New Roman' , 18 , 'normal' )) #乐 t.penup() t.goto( 150 , 30 ) t.pendown() t.pensize( 8 ) t.pencolor( 'red' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '谜' , font = ( 'Times New Roman' , 18 , 'normal' )) write_1() write_1() write_1() write_2() write_2() write_2() t.penup() t.goto( - 280 , - 200 ) t.pendown() t.pensize( 8 ) t.pencolor( 'red' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( 'Happy Lantern Festival !' , font = ( 'Times New Roman' , 15 , 'normal' )) |
三、拓展
下面将展示带有背景音乐的绘制灯笼的示例代码,有需要的可以参考一下
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
import os import pygame import turtle as t #播放音乐 pygame.mixer.init() pygame.mixer.music.load(r "F:\公众号\48.元宵节快乐\Sing, R. Sing! - おばちゃ!.mp3" ) pygame.mixer.music.set_volume( 0.5 ) pygame.mixer.music.play() ##画外轮廓 t.title( '元宵节字谜灯笼' ) t.setup(startx = 0 , starty = 0 ) #画灯笼提线 t.penup() t.goto( - 50 , 180 ) t.pendown() t.left( 100 ) t.pensize( 2 ) t.color( 'orangered' ) t.circle( - 15 , 80 ) t.right( 140 ) t.forward( 20 ) #画灯笼盖 t.penup() t.goto( - 57 , 179 ) t.pendown() t.left( 120 ) t.pensize( 1 ) #t.pencolor('gold') t.pencolor( '#fedf08' ) t.fillcolor( '#fedf08' ) #t.pencolor('orange') t.begin_fill() t.forward( 14 ) t.right( 15 ) t.forward( 20 ) t.right( 165 ) t.forward( 52 ) t.goto( - 57 , 179 ) t.end_fill() t.penup() t.goto( - 78 , 174 ) t.pendown() t.left( 135 ) t.pencolor( '#feb209' ) t.fillcolor( '#feb209' ) t.begin_fill() t.forward( 5 ) t.left( 45 ) t.forward( 47 ) t.goto( - 22 , 174 ) t.end_fill() #红色的柱子 t.penup() t.goto( - 70 , 170 ) t.pendown() t.color( 'red' ) t.begin_fill() t.right( 90 ) t.forward( 10 ) t.left( 90 ) t.forward( 40 ) t.left( 90 ) t.forward( 10 ) t.end_fill() def zz(x): t.penup() t.color( '#feb209' ) t.pensize( 1 ) t.begin_fill() t.goto(x, 160 ) t.forward( 10 ) t.right( 90 ) t.forward( 3 ) t.right( 90 ) t.forward( 10 ) t.right( 90 ) t.forward( 3 ) t.end_fill() t.right( 90 ) zz( - 64 ) #第一根柱子 zz( - 55 ) #第二根柱子 zz( - 45 ) #第三根柱子 zz( - 37 ) #第四根柱子 #棕色的柱子 t.penup() t.goto( - 74 , 160 ) t.pendown() t.color( '#7f4e1e' ) t.left( 90 ) t.begin_fill() t.circle( 2 , 90 ) t.forward( 5 ) t.left( 90 ) t.forward( 52 ) t.left( 90 ) t.forward( 5 ) t.circle( 2 , 90 ) t.forward( 50 ) t.end_fill() #灯笼外壳 t.penup() t.goto( - 76 , 153 ) t.pendown() t.begin_fill() t.color( 'orangered' ) t.circle( 30 , 90 ) t.forward( 70 ) t.circle( 30 , 90 ) t.forward( 52 ) t.circle( 30 , 90 ) t.forward( 70 ) t.circle( 30 , 90 ) t.end_fill() #棕色的柱子 t.penup() t.goto( - 74 , 23 ) t.pendown() t.color( '#7f4e1e' ) #t.left(90) t.begin_fill() t.circle( 2 , 90 ) t.forward( 5 ) t.left( 90 ) t.forward( 52 ) t.left( 90 ) t.forward( 5 ) t.circle( 2 , 90 ) t.forward( 50 ) t.end_fill() #黄色的线 t.penup() t.goto( - 50 , 15 ) t.pendown() t.left( 90 ) t.color( 'yellow' ) t.pensize( 1 ) t.forward( 25 ) #玫红色的球 t.right( 90 ) t.color( 'red' ) t.begin_fill() t.circle( 8 , 360 ) t.end_fill() #画流苏 t.penup() t.goto( - 50 , - 26 ) t.pendown() t.begin_fill() t.color( 'orangered' ) t.circle( 9 , 90 ) t.forward( 80 ) t.left( 90 ) t.forward( 18 ) t.left( 90 ) t.forward( 80 ) t.circle( 9 , 90 ) t.end_fill() #画流苏中黄色的圈 t.penup() t.goto( - 59 , - 42 ) t.left( 90 ) t.pendown() t.begin_fill() t.color( '#fedf08' ) t.forward( 10 ) t.left( 90 ) t.forward( 18 ) t.left( 90 ) t.forward( 10 ) t.left( 90 ) t.forward( 18 ) t.end_fill() #中文 t.hideturtle() t.penup() t.goto( - 72 , 120 ) t.pendown() t.pencolor( 'black' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '猜灯谜' , font = ( 'Comic Sans' , 11 , 'normal' )) t.penup() t.goto( - 87 , 91 ) t.pendown() t.pencolor( 'black' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '云 盖 中 秋 月' , font = ( 'Times New Roman' , 10 , 'normal' )) t.penup() t.goto( - 87 , 65 ) t.pendown() t.pencolor( 'black' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '雨 淋 元 宵 灯' , font = ( 'Times New Roman' , 10 , 'normal' )) t.penup() t.goto( - 84 , 40 ) t.pendown() t.pencolor( 'black' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '(打 一 成 语)' , font = ( 'Times New Roman' , 10 , 'normal' )) t.delay( 50 ) def write_1(): #元 t.penup() t.goto( 90 , 150 ) t.pendown() t.pensize( 8 ) t.pencolor( 'red' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '共' , font = ( 'Times New Roman' , 18 , 'normal' )) #宵 t.penup() t.goto( 90 , 120 ) t.pendown() t.pensize( 8 ) t.pencolor( 'red' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '饮' , font = ( 'Times New Roman' , 18 , 'normal' )) #节 t.penup() t.goto( 90 , 90 ) t.pendown() t.pensize( 8 ) t.pencolor( 'red' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '太' , font = ( 'Times New Roman' , 18 , 'normal' )) #快 t.penup() t.goto( 90 , 60 ) t.pendown() t.pensize( 8 ) t.pencolor( 'red' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '平' , font = ( 'Times New Roman' , 18 , 'normal' )) #乐 t.penup() t.goto( 90 , 30 ) t.pendown() t.pensize( 8 ) t.pencolor( 'red' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '酒' , font = ( 'Times New Roman' , 18 , 'normal' )) def write_2(): #元 t.penup() t.goto( 150 , 150 ) t.pendown() t.pensize( 8 ) t.pencolor( 'red' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '同' , font = ( 'Times New Roman' , 18 , 'normal' )) #宵 t.penup() t.goto( 150 , 120 ) t.pendown() t.pensize( 8 ) t.pencolor( 'red' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '猜' , font = ( 'Times New Roman' , 18 , 'normal' )) #节 t.penup() t.goto( 150 , 90 ) t.pendown() t.pensize( 8 ) t.pencolor( 'red' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '元' , font = ( 'Times New Roman' , 18 , 'normal' )) #快 t.penup() t.goto( 150 , 60 ) t.pendown() t.pensize( 8 ) t.pencolor( 'red' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '宵' , font = ( 'Times New Roman' , 18 , 'normal' )) #乐 t.penup() t.goto( 150 , 30 ) t.pendown() t.pensize( 8 ) t.pencolor( 'red' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( '谜' , font = ( 'Times New Roman' , 18 , 'normal' )) write_1() write_1() write_1() write_2() write_2() write_2() t.penup() t.goto( - 280 , - 200 ) t.pendown() t.pensize( 8 ) t.pencolor( 'red' ) #t.write('猜谜语', font=('Times New Roman', 12, 'normal')) t.write( 'Happy Lantern Festival !' , font = ( 'Times New Roman' , 15 , 'normal' )) |
以上就是Python绘制灯笼的示例代码的详细内容,更多关于Python绘制灯笼的资料请关注服务器之家其它相关文章!
原文链接:https://blog.csdn.net/qq_32532663/article/details/122991441