By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,761 Members | 950 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,761 IT Pros & Developers. It's quick & easy.

i have this code, but i don't know how to loop this code

P: 1
i have this code, but i don't know how to loop this code. please somebody help me :(

Expand|Select|Wrap|Line Numbers
  1. import turtle
  2. turtle.bgcolor("black")
  3. turtle.pensize(5)
  4.  
  5. turtle.penup()
  6. turtle.goto(-415,100)
  7. turtle.begin_fill()
  8. turtle.color("FireBrick")
  9. turtle.pendown()
  10. turtle.goto(-450,50)
  11. turtle.goto(-450,-350)
  12. turtle.goto(-380,-350)
  13. turtle.goto(-380,50)
  14. turtle.goto(-415,100)
  15. turtle.end_fill()
  16.  
  17. turtle.penup()
  18. turtle.goto(-350,180)
  19. turtle.pendown()
  20. turtle.begin_fill()
  21. turtle.color("MediumVioletRed")
  22. turtle.goto(-350,-350)
  23. turtle.goto(-290,-350)
  24. turtle.goto(-290,220)
  25. turtle.goto(-350,180)
  26. turtle.penup()
  27. turtle.goto(-340,190)
  28. turtle.pendown()
  29. turtle.goto(-340,220)
  30. turtle.goto(-320,220)
  31. turtle.goto(-320,200)
  32. turtle.end_fill()
  33.  
  34. turtle.penup()
  35. turtle.begin_fill()
  36. turtle.color("DarkSlateBlue")
  37. turtle.goto(-250,-350)
  38. turtle.pendown()
  39. turtle.goto(-250,100)
  40. turtle.goto(-230,100)
  41. turtle.goto(-230,250)
  42. turtle.goto(-220,250)
  43. turtle.goto(-220,270)
  44. turtle.goto(-210,270)
  45. turtle.goto(-210,250)
  46. turtle.goto(-200,250)
  47. turtle.goto(-200,100)
  48. turtle.goto(-180,100)
  49. turtle.goto(-180,-350)
  50. turtle.goto(-250,-350)
  51. turtle.end_fill()
  52.  
  53. turtle.penup()
  54. turtle.goto(-120,-350)
  55. turtle.begin_fill()
  56. turtle.color("RoyalBlue")
  57. turtle.pendown()
  58. turtle.goto(-120,150)
  59. turtle.goto(-40,150)
  60. turtle.goto(-40,-350)
  61. turtle.goto(-120,-350)
  62. turtle.penup()
  63. turtle.goto(-110,150)
  64. turtle.pendown()
  65. turtle.goto(-110,180)
  66. turtle.goto(-90,180)
  67. turtle.goto(-90,150)
  68. turtle.penup()
  69. turtle.goto(-80,150)
  70. turtle.pendown()
  71. turtle.goto(-80,170)
  72. turtle.goto(-70,170)
  73. turtle.goto(-70,150)
  74. turtle.penup()
  75. turtle.goto(-60,150)
  76. turtle.pendown()
  77. turtle.goto(-60,170)
  78. turtle.goto(-50,170)
  79. turtle.goto(-50,150)
  80. turtle.end_fill()
  81.  
  82. turtle.penup()
  83. turtle.goto(0,-350)
  84. turtle.begin_fill()
  85. turtle.color("MediumSeaGreen")
  86. turtle.pendown()
  87. turtle.goto(0,100)
  88. turtle.goto(50,150)
  89. turtle.goto(100,100)
  90. turtle.goto(100,-350)
  91. turtle.goto(0,-350)
  92. turtle.end_fill()
  93.  
  94. turtle.penup()
  95. turtle.goto(130,-350)
  96. turtle.begin_fill()
  97. turtle.color("SpringGreen")
  98. turtle.pendown()
  99. turtle.goto(130,80)
  100. turtle.goto(140,80)
  101. turtle.goto(140,250)
  102. turtle.goto(150,250)
  103. turtle.goto(150,260)
  104. turtle.goto(160,260)
  105. turtle.goto(165,300)
  106. turtle.goto(170,260)
  107. turtle.goto(180,260)
  108. turtle.goto(180,250)
  109. turtle.goto(190,250)
  110. turtle.goto(190,80)
  111. turtle.goto(200,80)
  112. turtle.goto(200,-350)
  113. turtle.goto(130,-350)
  114. turtle.end_fill()
  115.  
  116. turtle.penup()
  117. turtle.goto(240,-350)
  118. turtle.begin_fill()
  119. turtle.color("Gold")
  120. turtle.pendown()
  121. turtle.goto(240,80)
  122. turtle.goto(300,120)
  123. turtle.penup()
  124. turtle.goto(260,90)
  125. turtle.pendown()
  126. turtle.goto(260,110)
  127. turtle.goto(250,110)
  128. turtle.goto(250,85)
  129. turtle.penup()
  130. turtle.goto(300,120)
  131. turtle.pendown()
  132. turtle.goto(300,-350)
  133. turtle.goto(240,-350)
  134. turtle.end_fill()
  135.  
  136. turtle.penup()
  137. turtle.begin_fill()
  138. turtle.color("DarkOrange")
  139. turtle.goto(385,110)
  140. turtle.pendown()
  141. turtle.circle(15)
  142. turtle.end_fill()
  143. turtle.begin_fill()
  144. turtle.color("DarkOrange")
  145. turtle.penup()
  146. turtle.goto(350,-350)
  147. turtle.pendown()
  148. turtle.goto(350,100)
  149. turtle.goto(360,100)
  150. turtle.goto(360,120)
  151. turtle.goto(410,120)
  152. turtle.goto(410,100)
  153. turtle.goto(420,100)
  154. turtle.goto(420,-350)
  155. turtle.goto(350,-350)
  156. turtle.end_fill()
  157.  
  158. turtle.penup()
  159. turtle.goto(-280,-350)
  160. turtle.begin_fill()
  161. turtle.color("DarkViolet")
  162. turtle.pendown()
  163. turtle.goto(-280,30)
  164. turtle.goto(-270,30)
  165. turtle.goto(-270,50)
  166. turtle.goto(-260,50)
  167. turtle.goto(-260,30)
  168. turtle.goto(-250,30)
  169. turtle.goto(-250,50)
  170. turtle.goto(-240,50)
  171. turtle.goto(-240,30)
  172. turtle.goto(-210,30)
  173. turtle.goto(-210,-350)
  174. turtle.goto(-280,-350)
  175. turtle.end_fill()
  176.  
  177. turtle.penup()
  178. turtle.goto(-190,-350)
  179. turtle.begin_fill()
  180. turtle.color("DarkBlue")
  181. turtle.pendown()
  182. turtle.goto(-190,-30)
  183. turtle.goto(-130,-60)
  184. turtle.goto(-130,-350)
  185. turtle.goto(-190,-350)
  186. turtle.penup()
  187. turtle.goto(-150,-49)
  188. turtle.pendown()
  189. turtle.goto(-150,-30)
  190. turtle.goto(-140,-30)
  191. turtle.goto(-140,-54)
  192. turtle.end_fill()
  193.  
  194. turtle.penup()
  195. turtle.goto(-80,-350)
  196. turtle.begin_fill()
  197. turtle.color("DeepSkyBlue")
  198. turtle.pendown()
  199. turtle.goto(-80,-10)
  200. turtle.goto(20,-80)
  201. turtle.goto(20,-350)
  202. turtle.goto(-80,-350)
  203. turtle.end_fill()
  204.  
  205. turtle.penup()
  206. turtle.goto(100,-250)
  207. turtle.begin_fill()
  208. turtle.color("ForestGreen")
  209. turtle.circle(50)
  210. turtle.end_fill()
  211. turtle.penup()
  212. turtle.goto(50,-200)
  213. turtle.begin_fill()
  214. turtle.color("ForestGreen")
  215. turtle.pendown()
  216. turtle.goto(50,-350)
  217. turtle.goto(150,-350)
  218. turtle.goto(150,-200)
  219. turtle.goto(50,-200)
  220. turtle.end_fill()
  221.  
  222. turtle.penup()
  223. turtle.goto(180,-350)
  224. turtle.begin_fill()
  225. turtle.color("YellowGreen")
  226. turtle.pendown()
  227. turtle.goto(180,0)
  228. turtle.goto(260,0)
  229. turtle.goto(260,-350)
  230. turtle.goto(180,-350)
  231. turtle.end_fill()
  232.  
  233. turtle.penup()
  234. turtle.goto(290,-350)
  235. turtle.begin_fill()
  236. turtle.color("DarkGoldenrod")
  237. turtle.pendown()
  238. turtle.goto(290,-100)
  239. turtle.goto(360,-100)
  240. turtle.goto(360,-350)
  241. turtle.goto(290,-350)
  242. turtle.end_fill()
  243.  
  244. turtle.penup()
  245. turtle.goto(390,-350)
  246. turtle.begin_fill()
  247. turtle.color("Red")
  248. turtle.pendown()
  249. turtle.goto(390,0)
  250. turtle.goto(430,0)
  251. turtle.goto(430,20)
  252. turtle.goto(440,20)
  253. turtle.goto(440,0)
  254. turtle.goto(450,0)
  255. turtle.goto(450,-350)
  256. turtle.goto(390,-350)
  257. turtle.end_fill()
  258.  
  259. turtle.penup()
  260. turtle.goto(-420,-350)
  261. turtle.begin_fill()
  262. turtle.color("DeepPink")
  263. turtle.pendown()
  264. turtle.goto(-420,-170)
  265. turtle.goto(-340,-210)
  266. turtle.goto(-340,-350)
  267. turtle.goto(-420,-350)
  268. turtle.end_fill()
  269.  
  270. turtle.penup()
  271. turtle.goto(-310,-350)
  272. turtle.begin_fill()
  273. turtle.color("MediumOrchid")
  274. turtle.pendown()
  275. turtle.goto(-310,-150)
  276. turtle.goto(-240,-150)
  277. turtle.goto(-240,-350)
  278. turtle.goto(-310,-350)
  279. turtle.end_fill()
  280.  
  281. turtle.penup()
  282. turtle.goto(-160,-350)
  283. turtle.begin_fill()
  284. turtle.color("MediumBlue")
  285. turtle.goto(-160,-200)
  286. turtle.goto(-150,-200)
  287. turtle.goto(-150,-190)
  288. turtle.goto(-140,-190)
  289. turtle.goto(-140,-200)
  290. turtle.goto(-100,-200)
  291. turtle.goto(-100,-350)
  292. turtle.goto(-160,-350)
  293. turtle.end_fill()
  294.  
  295. turtle.done()
May 27 '13 #1
Share this Question
Share on Google+
2 Replies

Oralloy
Expert 100+
P: 983
First off, please use code tags around your work.

Secondly, what are you actually trying to accomplish?
May 27 '13 #2

Expert 100+
P: 626
For just drawing the objects you would use a function and a for loop. See one of the tutorials at the Python.org WIKI.
functions http://www.rexx.com/~dkuhlman/python...00000000000000
for loops http://www.rexx.com/~dkuhlman/python...00000000000000
lists and tuples http://www.rexx.com/~dkuhlman/python...00000000000000
Expand|Select|Wrap|Line Numbers
  1. import turtle
  2. turtle.bgcolor("black")
  3. turtle.pensize(5)
  4.  
  5. def draw_object(startx, starty, color, points_list):
  6.     turtle.penup()
  7.     turtle.goto(startx, starty)
  8.     turtle.begin_fill()
  9.     turtle.color(color)
  10.     turtle.pendown()
  11.     for x,y in points_list:
  12.         turtle.goto(x, y)
  13.     turtle.end_fill()
  14.  
  15. draw_object(-415, 100, "FireBrick", 
  16.          [[-450,50], [-450,-350], [-380,-350],
  17.           [-380,50], [-415,100]])
  18. draw_object(-250, -350, "DarkSlateBlue", 
  19.          [(-250,100), (-230,100), (-230,250),
  20.           (-220,250), (-220,270), (-210,270),
  21.           (-210,250), (-200,250), (-200,100),
  22.           (-180,100), (-180,-350), (-250,-350)])
  23. raw_input() 
May 27 '13 #3

Post your reply

Sign in to post your reply or Sign up for a free account.