Python选修课第二届Turtle绘图大赛

Posted haochunlin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python选修课第二届Turtle绘图大赛相关的知识,希望对你有一定的参考价值。

1)Partner:

学号:20181505025,郝春霖

学号:20181001113,杨禹凤

2)作品图示:

技术图片

3)源代码:

  1 import turtle
  2 import random
  3 import time
  4 
  5 turtle.setup(0.9,0.9,None,None)
  6 turtle.penup()
  7 turtle.fd(-318)
  8 turtle.pendown()
  9 turtle.pensize(3)#初始线条
 10 turtle.pencolor("brown")
 11 turtle.speed(0)#画笔速度
 12 
 13 #整体背景颜色
 14 turtle.bgcolor("black")
 15 
 16 #埃菲尔铁塔
 17 turtle.seth(0)
 18 turtle.fd(30)
 19 turtle.seth(100)
 20 turtle.fd(75)
 21 turtle.seth(98)
 22 turtle.fd(75)
 23 turtle.seth(95)
 24 turtle.fd(60)
 25 turtle.seth(70)
 26 turtle.fd(25)
 27 turtle.seth(180)
 28 turtle.fd(10)
 29 turtle.seth(90)
 30 turtle.fd(15)
 31 turtle.seth(0)
 32 turtle.fd(5)
 33 turtle.seth(90)
 34 turtle.circle(18,90)
 35 turtle.seth(90)
 36 turtle.fd(30)
 37 turtle.seth(-90)
 38 turtle.fd(15)
 39 turtle.seth(180)
 40 turtle.fd(5)
 41 turtle.seth(0)
 42 turtle.fd(10)
 43 turtle.seth(180)
 44 turtle.fd(5)
 45 turtle.seth(-90)
 46 turtle.fd(15)
 47 turtle.seth(180)
 48 turtle.circle(18,90)
 49 turtle.seth(0)
 50 turtle.fd(5)
 51 turtle.seth(-90)
 52 turtle.fd(15)
 53 turtle.seth(0)
 54 turtle.fd(28)
 55 turtle.seth(180)
 56 turtle.fd(28)
 57 turtle.seth(180)
 58 turtle.fd(10)
 59 turtle.seth(-70)
 60 turtle.fd(25)
 61 turtle.seth(-95)
 62 turtle.fd(60)
 63 turtle.seth(-98)
 64 turtle.fd(75)
 65 turtle.seth(-100)
 66 turtle.fd(75)
 67 turtle.seth(0)
 68 turtle.fd(86)
 69 
 70 #铁塔上部分内部线条
 71 turtle.pensize(1)
 72 turtle.seth(155)
 73 turtle.fd(88)
 74 turtle.seth(20)
 75 turtle.fd(75)
 76 turtle.seth(160)
 77 turtle.fd(66)
 78 turtle.seth(20)
 79 turtle.fd(59)
 80 turtle.seth(160)
 81 turtle.fd(54)
 82 turtle.seth(20)
 83 turtle.fd(49)
 84 turtle.seth(160)
 85 turtle.fd(43)
 86 turtle.seth(20)
 87 turtle.fd(39)
 88 turtle.seth(160)
 89 turtle.fd(37)
 90 turtle.seth(20)
 91 turtle.fd(34)
 92 turtle.seth(160)
 93 turtle.fd(32)
 94 turtle.seth(11)
 95 turtle.fd(28)
 96 turtle.seth(180)
 97 turtle.fd(27)
 98 turtle.seth(90)
 99 turtle.fd(10)
100 turtle.seth(0)
101 turtle.fd(27)
102 turtle.seth(-90)
103 turtle.fd(10)
104 turtle.seth(180)
105 turtle.fd(27)
106 turtle.seth(-11)
107 turtle.fd(28)
108 turtle.seth(-160)
109 turtle.fd(32)
110 turtle.seth(-20)
111 turtle.fd(34)
112 turtle.seth(-160)
113 turtle.fd(37)
114 turtle.seth(-20)
115 turtle.fd(39)
116 turtle.seth(-160)
117 turtle.fd(43)
118 turtle.seth(-20)
119 turtle.fd(49)
120 turtle.seth(-160)
121 turtle.fd(54)
122 turtle.seth(-20)
123 turtle.fd(59)
124 turtle.seth(-160)
125 turtle.fd(66)
126 turtle.seth(-20)
127 turtle.fd(75)
128 turtle.seth(-155)
129 turtle.fd(88)
130 turtle.seth(0)
131 turtle.fd(43.4)
132 turtle.seth(90)
133 turtle.fd(225)
134 turtle.seth(-90)
135 turtle.fd(225)
136 turtle.seth(180)
137 turtle.fd(43.2)
138 
139 #铁塔中部线条
140 turtle.pensize(3)
141 turtle.seth(-115)
142 turtle.fd(40)
143 turtle.seth(65)
144 turtle.fd(40)
145 turtle.seth(0)
146 turtle.fd(87)
147 turtle.seth(-65)
148 turtle.fd(40)
149 turtle.seth(180)
150 turtle.fd(10)
151 turtle.seth(90)
152 turtle.circle(8,180)
153 turtle.seth(180)
154 turtle.fd(5)
155 turtle.seth(90)
156 turtle.circle(8,180)
157 turtle.seth(180)
158 turtle.fd(5)
159 turtle.seth(90)
160 turtle.circle(8,180)
161 turtle.seth(180)
162 turtle.fd(5)
163 turtle.seth(90)
164 turtle.circle(8,180)
165 turtle.seth(180)
166 turtle.fd(5)
167 turtle.seth(90)
168 turtle.circle(8,180)
169 turtle.seth(180)
170 turtle.fd(10)
171 turtle.seth(0)
172 turtle.fd(130)
173 turtle.seth(-145)
174 turtle.fd(25)
175 turtle.seth(180)
176 turtle.fd(100)
177 turtle.seth(145)
178 turtle.fd(25)
179 turtle.seth(0)
180 turtle.fd(10)
181 turtle.seth(180)
182 turtle.fd(10)
183 turtle.seth(-40)
184 turtle.fd(25)
185 turtle.seth(-110)
186 turtle.fd(60)
187 turtle.seth(0)
188 turtle.fd(30)
189 turtle.seth(70)
190 turtle.fd(50)
191 turtle.seth(180)
192 turtle.fd(30)
193 
194 #铁塔左中部内部线条
195 turtle.pensize(1)
196 turtle.seth(-30)
197 turtle.fd(30)
198 turtle.seth(-160)
199 turtle.fd(40)
200 turtle.seth(-35)
201 turtle.fd(31)
202 turtle.seth(106)
203 turtle.fd(49)
204 turtle.seth(70)
205 turtle.fd(10)
206 turtle.seth(0)
207 turtle.fd(100)
208 
209 #铁塔中部线条
210 turtle.pensize(3)
211 turtle.seth(-70)
212 turtle.fd(60)
213 turtle.seth(180)
214 turtle.fd(30)
215 turtle.seth(110)
216 turtle.fd(50)
217 turtle.seth(0)
218 turtle.fd(30)
219 
220 #铁塔右中部内部线条
221 turtle.pensize(1)
222 turtle.seth(-150)
223 turtle.fd(30)
224 turtle.seth(-20)
225 turtle.fd(40)
226 turtle.seth(-145)
227 turtle.fd(31)
228 turtle.seth(74)
229 turtle.fd(49)
230 turtle.seth(180)
231 turtle.fd(30)
232 
233 #铁塔下部线条
234 turtle.pensize(3)
235 turtle.seth(90)
236 turtle.fd(8)
237 turtle.seth(180)
238 turtle.fd(45)
239 turtle.seth(-90)
240 turtle.fd(8)
241 turtle.seth(-90)
242 turtle.fd(50)
243 turtle.seth(180)
244 turtle.fd(60)
245 turtle.seth(-90)
246 turtle.fd(20)
247 turtle.seth(0)
248 turtle.fd(165)
249 turtle.seth(90)
250 turtle.fd(20)
251 turtle.seth(180)
252 turtle.fd(60)
253 turtle.seth(90)
254 turtle.fd(50)
255 turtle.seth(-90)
256 turtle.fd(70)
257 turtle.seth(180)
258 turtle.fd(45)
259 turtle.seth(90)
260 turtle.fd(20)
261 turtle.seth(-90)
262 turtle.fd(20)
263 turtle.seth(-120)
264 turtle.fd(120)
265 turtle.pensize(6)
266 turtle.seth(180)
267 turtle.fd(50)
268 turtle.pensize(3)
269 turtle.seth(60)
270 turtle.fd(120)
271 turtle.seth(0)
272 turtle.fd(95)
273 turtle.seth(-60)
274 turtle.fd(120)
275 turtle.pensize(6)
276 turtle.seth(0)
277 turtle.fd(50)
278 turtle.pensize(3)
279 turtle.seth(120)
280 turtle.fd(120)
281 turtle.pensize(1)
282 turtle.seth(-150)
283 turtle.fd(41)
284 turtle.seth(-20)
285 turtle.fd(60)
286 turtle.seth(-150)
287 turtle.fd(42)
288 turtle.seth(-40)
289 turtle.fd(62)
290 turtle.seth(97)
291 turtle.fd(62)
292 turtle.seth(120)
293 turtle.fd(48)
294 turtle.seth(180)
295 turtle.fd(145)
296 turtle.seth(-30)
297 turtle.fd(41)
298 turtle.seth(-161)
299 turtle.fd(60)
300 turtle.seth(-30)
301 turtle.fd(42)
302 turtle.seth(-140)
303 turtle.fd(65)
304 turtle.seth(81)
305 turtle.fd(62)
306 turtle.seth(60)
307 turtle.fd(47)
308 turtle.seth(0)
309 turtle.fd(50)
310 turtle.seth(-120)
311 turtle.fd(60)
312 turtle.pensize(3)
313 turtle.seth(0)
314 turtle.fd(25)
315 turtle.seth(90)
316 turtle.circle(-30,180)
317 turtle.seth(0)
318 turtle.fd(22)
319 turtle.penup()
320 turtle.fd(200)
321 turtle.pendown()
322 
323 
324 
325 #月亮
326 turtle.penup()
327 turtle.goto(600,370)
328 turtle.pendown()
329 turtle.begin_fill()
330 turtle.color("yellow")
331 turtle.circle(-40,-360)
332 turtle.end_fill()
333 
334 #星星
335 for i in range(80):
336     turtle.pensize(1)
337     x=random.randint(-900,900)
338     y=random.randint(100,500)
339     turtle.penup()
340     turtle.pencolor("yellow")
341     turtle.goto(x,y)
342     turtle.pendown()
343     turtle.seth(45)
344     for j in range(3):
345         turtle.fd(1)
346         turtle.right(90)
347     turtle.fd(1)
348 
349 #公路小道左侧
350 turtle.penup()
351 turtle.goto(-360,-183)
352 turtle.pendown()
353 turtle.pencolor("gray")
354 turtle.pensize(2)
355 turtle.seth(-70)
356 turtle.fd(300)
357 
358 #公路小道右侧
359 turtle.penup()
360 turtle.goto(-302,-183)
361 turtle.pendown()
362 turtle.pencolor("gray")
363 turtle.pensize(2)
364 turtle.seth(-47)
365 turtle.fd(300)
366 
367 #马路线
368 turtle.penup()
369 turtle.goto(-330,-183)
370 turtle.pendown()
371 turtle.pencolor("gray")
372 turtle.pensize(3)
373 turtle.seth(-55)
374 turtle.fd(50)
375 turtle.penup()
376 turtle.goto(-290,-240)
377 turtle.pendown()
378 turtle.pencolor("gray")
379 turtle.pensize(4)
380 turtle.seth(-55)
381 turtle.fd(60)
382 turtle.penup()
383 turtle.goto(-240,-315)
384 turtle.pendown()
385 turtle.pencolor("gray")
386 turtle.pensize(5)
387 turtle.seth(-55)
388 turtle.fd(90)
389 
390 #城市背景
391 turtle.penup()
392 turtle.goto(-481,-236)
393 turtle.pendown()
394 turtle.pencolor("white")
395 turtle.pensize(2)
396 
397 #高楼(左侧)
398 for i in range(10):
399     turtle.pensize(2)
400     z=random.randint(200,350)#
401     x=random.randint(20,50)
402     turtle.seth(90)
403     turtle.fd(z)
404     turtle.seth(180)
405     turtle.fd(x)
406     turtle.seth(-90)
407     turtle.fd(z)
408     turtle.seth(0)
409     turtle.fd(x)
410     turtle.backward(x)   
411 #高楼(右侧)
412 turtle.penup()
413 turtle.goto(-180,-236)
414 turtle.pendown()    
415 for i in range(30):
416     turtle.pensize(2)
417     z=random.randint(200,350)
418     x=random.randint(20,50)
419     turtle.seth(90)
420     turtle.fd(z)
421     turtle.seth(0)
422     turtle.fd(x)
423     turtle.seth(-90)
424     turtle.fd(z)
425     turtle.seth(180)
426     turtle.fd(x)
427     turtle.backward(x)
428     
429 #街边树木(左侧)
430 for i in range(6):
431     turtle.penup()
432     turtle.goto(-730+50*i,-280)
433     turtle.pendown()
434     turtle.pencolor("brown")
435     turtle.pensize(2)
436     turtle.seth(90)
437     turtle.fd(60)
438     for j in range(22):
439         turtle.pencolor("green")
440         turtle.seth(35+j*5)
441         turtle.fd(50)
442         turtle.backward(50)
443         
444 #街边树木(右侧)
445 for i in range(20):
446     turtle.penup()
447     turtle.goto(-180+50*i,-280)
448     turtle.pendown()
449     turtle.pencolor("brown")
450     turtle.pensize(2)
451     turtle.seth(90)
452     turtle.fd(60)
453     for j in range(22):
454         turtle.pencolor("green")
455         turtle.seth(35+j*5)
456         turtle.fd(50)
457         turtle.backward(50)        
458 
459 #情人
460 turtle.penup()
461 turtle.goto(220,-330)
462 turtle.pendown()
463 turtle.pensize(2)
464 turtle.begin_fill()
465 turtle.color("brown")
466 turtle.seth(0)
467 turtle.fd(80)
468 turtle.seth(-90)
469 turtle.fd(30)
470 turtle.seth(180)
471 turtle.fd(80)
472 turtle.seth(90)
473 turtle.fd(30)
474 turtle.end_fill()
475 turtle.pencolor("gray")
476 turtle.seth(0)
477 turtle.fd(25)
478 turtle.circle(10,360)
479 turtle.fd(30)
480 turtle.circle(10,360)
481 turtle.penup()
482 turtle.goto(280,-315)
483 turtle.pendown()
484 turtle.pensize(4)
485 turtle.seth(-90)
486 turtle.fd(20)
487 for i in range(6):
488     turtle.penup()
489     turtle.goto(220+16*i,-360)
490     turtle.pendown()
491     turtle.pensize(2)
492     turtle.seth(-90)
493     if i==0 and i==5:
494         turtle.fd(30)
495     else:
496         turtle.fd(15)
497    
498 #I Love You字体
499 turtle.penup()
500 turtle.goto(-100,0)
501 turtle.pendown()
502 turtle.pencolor("red")
503 turtle.pensize(3)
504 turtle.hideturtle()#隐藏
505 turtle.write("",  font = ("Times", 300,"bold"))
506 #turtle.hideturtle()#隐藏
507 time.sleep(1)#暂留1秒
508 turtle.undo()
509 turtle.penup()
510 turtle.goto(-100,200)
511 turtle.pendown()
512 turtle.pencolor("pink")
513 turtle.write("I Love You",font = ("Times", 38,"bold"))        
514 turtle.hideturtle()#隐藏

4)代码演示:

链接:http://v.youku.com/v_show/id_XNDE3Mzg1NzI3Ng==.html?spm=a2h3j.8428770.3416059.1

 

以上是关于Python选修课第二届Turtle绘图大赛的主要内容,如果未能解决你的问题,请参考以下文章

某篮球巨星(第二届Turtle绘图大赛)

turtle的简单绘图

每日一练:Python代码绘制航海王草帽路飞,打饭阿姨也能跟着学会的Turtle海龟绘图系列

每日一练:Python代码绘制航海王草帽路飞,打饭阿姨也能跟着学会的Turtle海龟绘图系列

Python 代码绘制航海王四皇大妈(BIG MOM) - 门卫大爷也能跟着学会的Turtle海龟绘图系列

python 的一个绘图代码