【中秋征文】使用Python中秋节程序员的浪漫《嫦娥奔月》

我会带着你远行 2024-05-07 17:08 170阅读 0赞

一、前言

大家好,我是猿童学?,欢迎来到中秋创作第三期,祝大家中秋节快乐。嫦娥相信大家不会陌生,她是中国古代神话中的人物。熟话说:“嫦娥飞天去,神州归来也”,今天使用海龟库给大家画一幅嫦娥奔月图。

9ab7d52c160b96b515df91cf927e2b44.jpeg

嫦娥飞天去,神州归来也

二、效果展示

让大家看看嫦娥小姐姐。???

191a7c26976e4fe4b9eb672f762ec063.gif

3e2a1edcc8c144aab983d393f216eb86.gif

中秋·赏月吟

花好月圆时,中秋佳节至,手中白瓷杯,月在杯中醉。

饮一掬月色,话一世浮沉,忽觉眼前人,更胜天上月。

三、代码解析

将代码模块化,使用函数来划分,一个一个的分解,到最后在调用组合,使复杂的问题简单化。

3.1初始化背景,设置窗口大小及背景颜色

  1. def draw_bg():
  2. t.penup()
  3. t.goto(-700, -350)
  4. t.pendown()
  5. t.color((30, 30, 60), (30, 30, 60))
  6. t.begin_fill()
  7. t.goto(700, -350)
  8. t.goto(700, 350)
  9. t.goto(-700, 350)
  10. t.goto(-700, -350)
  11. t.end_fill()
  12. t.penup()
  13. def init_draw():
  14. t.setup(1400, 700, startx=100, starty=100)
  15. t.colormode(255)
  16. # 这样设置背景导出的图片看不到背景
  17. # t.bgcolor(30, 30, 60)
  18. # 画背景
  19. draw_bg()

bc2750c5e6ae47859714043279736ea4.png

3.2 画星星,随机生成不同颜色的星星

  1. def draw_star(s):
  2. t.begin_fill()
  3. for _ in range(6):
  4. t.forward(s)
  5. t.right(270)
  6. t.forward(s)
  7. t.right(150)
  8. t.end_fill()
  9. def draw_stars(sn):
  10. for _ in range(sn):
  11. t.penup()
  12. t.goto(r.randint(-500, 600), r.randint(-100, 300))
  13. t.pendown()
  14. c = r.choice(('purple', 'green', 'yellow', 'white', 'blue'))
  15. t.color(c, c)
  16. t.seth(30)
  17. draw_star(r.randint(2, 5))

5b1ca503b3284d12bf11ba21bf831cc9.gif

3.3 画假山

  1. def draw_mount(d, a):
  2. t.penup()
  3. t.goto(-699-a*d, math.cos(a*(-699+699)/d)*d-100*a)
  4. t.pendown()
  5. t.begin_fill()
  6. for x in range(-700, 1000):
  7. t.goto(x-a*d, math.cos(a*(x+699)/d)*d-100*a)
  8. t.goto(700, -700)
  9. t.goto(-700, -700)
  10. t.goto(-699-a*d, math.cos(a*(-699+699)/d)*d-100*a)
  11. t.end_fill()
  12. def draw_mounts():
  13. t.color('#90EE90', '#90EE90')
  14. draw_mount(80, 1)
  15. t.color('#87CEEB', '#87CEEB')
  16. draw_mount(70, 1.75)
  17. t.color('#7D9EC0', '#7D9EC0')
  18. draw_mount(60, 2.5)

0fc39b311da640ccaf39967dee684224.gif

3.4 画月亮,有不同形状的月亮选择,圆的月亮,弯的月亮。

  1. def draw_moon():
  2. t.penup()
  3. # t.goto(-510, 300)
  4. t.goto(-550, 300)
  5. t.pendown()
  6. t.color('yellow', 'yellow')
  7. t.begin_fill()
  8. # 弯月
  9. # t.right(15)
  10. # t.circle(-60, 220)
  11. # t.right(140)
  12. # t.circle(60, 140)
  13. # 圆月
  14. t.right(15)
  15. t.circle(-100)
  16. t.end_fill()

0440eb2c8142454989b297013e10e591.png

3.5 画广寒宫

  1. def draw_frool(y, j, w, h):
  2. # 房框
  3. t.penup()
  4. t.goto(y, j)
  5. t.pendown()
  6. t.goto(y-w, j)
  7. t.goto(y-w, j+h)
  8. t.goto(y, j+h)
  9. t.goto(y, j)
  10. # 左房檐
  11. t.penup()
  12. t.goto(y-w, j+h)
  13. t.seth(180)
  14. t.pendown()
  15. t.circle(-(int(w/3)), 60)
  16. # 右房檐
  17. t.penup()
  18. t.goto(y, j+h)
  19. t.seth(0)
  20. t.pendown()
  21. t.circle(int(w/3), 60)
  22. # 房门
  23. if y==-480:
  24. t.penup()
  25. t.goto(y-int(w*0.3), j)
  26. t.pendown()
  27. t.goto(y-int(w*0.3), j+int(h/2))
  28. t.goto(y-w+int(w*0.3), j+int(h/2))
  29. t.goto(y-w+int(w*0.3), j)
  30. t.penup()
  31. t.goto(y-int(w*0.5), j+int(h/2))
  32. t.pendown()
  33. t.goto(y-int(w*0.5), j)
  34. t.penup()
  35. t.goto(y-int(w*0.42), j+int(h/4))
  36. t.pendown()
  37. t.circle(0.5)
  38. t.penup()
  39. t.goto(y-int(w*0.58), j+int(h/4))
  40. t.pendown()
  41. t.circle(0.5)
  42. # 画窗户
  43. else:
  44. t.penup()
  45. t.goto(y-int(w*0.2), j+int(h*0.2))
  46. t.pendown()
  47. t.goto(y-w+int(w*0.2), j+int(h*0.2))
  48. t.goto(y-w+int(w*0.2), j+h-int(h*0.2))
  49. t.goto(y-int(w*0.2), j+h-int(h*0.2))
  50. t.goto(y-int(w*0.2), j+int(h*0.2))
  51. t.penup()
  52. t.goto(y-int(w*0.5), j+int(h*0.2))
  53. t.pendown()
  54. t.goto(y-int(w*0.5), j+h-int(h*0.2))
  55. t.penup()
  56. t.goto(y-int(w*0.2), j+int(h*0.5))
  57. t.pendown()
  58. t.goto(y-w+int(w*0.2), j+int(h*0.5))
  59. def draw_palace():
  60. t.color('white')
  61. t.width(4)
  62. draw_frool(-480, 160, 100, 60)
  63. draw_frool(-500, 220, 60, 25)
  64. draw_frool(-510, 245, 40, 20)
  65. draw_frool(-518, 265, 24, 12)
  66. draw_frool(-524, 277, 12, 8)
  67. draw_frool(-528, 285, 4, 2)

d4eb346c169040bc883db3adb5d07938.gif

3.6 画树

  1. def draw_tree(s, f=5, h=90):
  2. if f == 0:
  3. return
  4. t.pendown()
  5. t.seth(h)
  6. t.fd(s+10 if f==5 else s)
  7. draw_tree(s>>1, f-1, h+45)
  8. t.penup()
  9. t.seth(h+45+180); t.fd(s>>1)
  10. draw_tree(s>>1, f-1, h-45)
  11. t.penup()
  12. t.seth(h-45+180); t.fd(s>>1)

fc08352c7d7c4983b0b1c9dacef628ed.gif

3.7 画吴刚

  1. def draw_WuGang():
  2. t.width(2)
  3. # 头
  4. ## 脸
  5. t.penup()
  6. t.goto(-472, 162)
  7. t.seth(70)
  8. t.pendown()
  9. t.color('black')
  10. t.circle(6, 140)
  11. t.color('#b3c518')
  12. t.circle(6, 220)
  13. ## 发髻
  14. t.penup()
  15. t.circle(6, 10)
  16. t.pendown()
  17. t.color('black')
  18. t.begin_fill()
  19. t.circle(-2)
  20. t.end_fill()
  21. ## 眼
  22. t.penup()
  23. t.goto(-478, 165)
  24. t.seth(90)
  25. t.pendown()
  26. t.fd(2)
  27. ## 嘴
  28. t.penup()
  29. t.goto(-481, 161)
  30. t.seth(-30)
  31. t.pendown()
  32. t.color('pink')
  33. t.circle(3, 50)
  34. # 身体
  35. ## 腰
  36. t.penup()
  37. t.color('#386650', '#386650')
  38. t.goto(-482, 143)
  39. t.pendown()
  40. t.seth(-110)
  41. t.fd(12)
  42. t.circle(1, 160)
  43. t.fd(12)
  44. t.right(120)
  45. t.fd(12)
  46. t.circle(1, 160)
  47. t.fd(14)
  48. ## 右肩
  49. t.penup()
  50. t.color('#5cd29b')
  51. t.seth(-1)
  52. t.goto(-475, 158)
  53. t.pendown()
  54. t.circle(-6, 90)
  55. ## 右手
  56. t.fd(3)
  57. t.color(skin)
  58. t.left(149)
  59. t.fd(1)
  60. t.circle(-2, 180)
  61. t.fd(2)
  62. t.circle(-4, 150)
  63. t.color('#4cd29b')
  64. t.fd(3)
  65. # 身体中插入一个斧子 #
  66. ###################
  67. ## 斧子把
  68. t.penup()
  69. t.goto(-486, 143)
  70. t.color('brown')
  71. t.pendown()
  72. t.goto(-456, 152)
  73. ## 斧子头
  74. t.penup()
  75. t.width(1)
  76. t.goto(-458, 148)
  77. t.color('black', 'black')
  78. t.pendown()
  79. t.begin_fill()
  80. t.seth(190)
  81. t.fd(1)
  82. t.right(90)
  83. t.fd(3)
  84. t.circle(8, 60)
  85. t.right(110)
  86. t.circle(-8, 80)
  87. t.right(110)
  88. t.circle(8, 60)
  89. t.fd(4)
  90. t.end_fill()
  91. ###################
  92. ## 左肩
  93. t.penup()
  94. t.width(2)
  95. t.color('#4cd29b')
  96. t.seth(180)
  97. t.goto(-482, 158)
  98. t.pendown()
  99. t.circle(5, 90)
  100. ## 左手
  101. t.fd(5)
  102. t.color(skin)
  103. t.circle(2, 60)
  104. t.fd(4)
  105. t.circle(2, 180)
  106. t.fd(3)
  107. t.color('#5cd29b')
  108. t.circle(-1, 60)
  109. t.fd(3)

0f5f1c0ad6db4d0db789ea53abedd724.gif

3.8 画嫦娥姐姐

  1. def draw_ChangE():
  2. lx, ly = -530, 170
  3. # 左手
  4. t.penup()
  5. t.color(skin)
  6. t.width(4)
  7. t.goto(lx, ly)
  8. t.seth(50)
  9. t.pendown()
  10. t.fd(10)
  11. t.circle(-3, 180)
  12. t.right(170)
  13. t.circle(-6, 180)
  14. t.circle(-50, 20)
  15. # 左袖
  16. t.penup()
  17. t.color('red')
  18. t.goto(lx, ly)
  19. t.seth(-140)
  20. t.pendown()
  21. t.fd(16)
  22. t.penup()
  23. t.goto(lx, ly)
  24. t.seth(-50)
  25. t.pendown()
  26. t.fd(30)
  27. t.right(90)
  28. t.fd(10)
  29. t.circle(-50, 40)
  30. # 衣服
  31. t.color('#f3dd64')
  32. t.penup()
  33. t.right(90)
  34. t.fd(10)
  35. t.right(180)
  36. t.pendown()
  37. t.circle(-100, 8)
  38. t.circle(-20, 80)
  39. t.circle(-100, 11)
  40. # 衣服2
  41. t.penup()
  42. t.circle(-100, -11)
  43. t.circle(-20, -80)
  44. t.fd(8)
  45. t.pendown()
  46. t.circle(-100, 6)
  47. t.circle(-15, 82)
  48. t.circle(-40, 35)
  49. # 衣服-裙
  50. t.color('red')
  51. t.penup()
  52. t.circle(-40, -35)
  53. t.circle(-15, -82)
  54. t.fd(10)
  55. t.right(10)
  56. t.pendown()
  57. t.circle(-100, 60)
  58. t.right(60)
  59. t.circle(-100, 60)
  60. t.right(60)
  61. t.circle(-200, 2)
  62. # 右袖
  63. t.penup()
  64. t.circle(-200, -2)
  65. t.right(-60)
  66. t.circle(-100, -60)
  67. t.right(-60)
  68. t.circle(-100, -60)
  69. t.right(-10)
  70. t.fd(-6)
  71. t.circle(-100, -6)
  72. t.fd(-8)
  73. t.circle(-20, 80)
  74. t.circle(-100, 12)
  75. t.right(110)
  76. t.fd(10)
  77. t.right(180)
  78. t.pendown()
  79. t.circle(-50, 50)
  80. t.right(70)
  81. t.circle(-50, 40)
  82. t.right(57)
  83. t.circle(-200, 10)
  84. # 右手
  85. t.penup()
  86. t.circle(-200, -10)
  87. t.right(-57)
  88. t.circle(-50, -4)
  89. t.color(skin)
  90. t.left(80)
  91. t.circle(10, 15)
  92. t.pendown()
  93. t.circle(10, 190)
  94. # 下方飘带
  95. t.penup()
  96. t.circle(10, -90)
  97. t.seth(-140)
  98. t.color('#f3dd64')
  99. t.circle(-10, 10)
  100. t.pendown()
  101. t.circle(-10, 100)
  102. t.circle(-40, 20)
  103. t.circle(40, 70)
  104. t.left(80)
  105. t.circle(60, 40)
  106. t.left(60)
  107. t.circle(-30, 50)
  108. t.circle(20, 80)
  109. t.fd(25)
  110. # 脸
  111. t.penup()
  112. t.goto(lx, ly)
  113. t.seth(-140)
  114. t.fd(16)
  115. t.seth(-100)
  116. t.color(skin)
  117. t.pendown()
  118. t.circle(-30, 100)
  119. t.color('black')
  120. t.begin_fill()
  121. t.circle(-30, 30)
  122. # 耳朵
  123. t.left(100)
  124. t.circle(-10, 180)
  125. t.circle(-2, 60)
  126. t.circle(-40, 20)
  127. # 头发
  128. t.left(150)
  129. t.circle(-10, 90)
  130. t.circle(80, 10)
  131. t.circle(30, 60)
  132. t.right(100)
  133. t.circle(-20, 70)
  134. t.circle(3, 160)
  135. t.circle(25, 90)
  136. t.left(20)
  137. t.fd(20)
  138. t.right(80)
  139. t.circle(20, 150)
  140. t.right(80)
  141. t.circle(8, 180)
  142. t.right(90)
  143. t.fd(10)
  144. t.right(110)
  145. t.circle(10, 100)
  146. t.right(110)
  147. t.fd(12)
  148. t.circle(8, 110)
  149. t.right(50)
  150. t.circle(12, 70)
  151. t.circle(2, 50)
  152. t.circle(180, 25)
  153. t.end_fill()
  154. # 发髻
  155. t.penup()
  156. t.circle(180, -25)
  157. t.circle(2, -50)
  158. t.circle(12, -70)
  159. t.right(-50)
  160. t.circle(8, -110)
  161. t.fd(-12)
  162. t.right(-110)
  163. t.circle(10, -100)
  164. t.right(-110)
  165. t.fd(-10)
  166. t.right(-90)
  167. t.circle(8, -180)
  168. t.fd(-25)
  169. t.left(20)
  170. t.color('yellow')
  171. t.width(1)
  172. t.pendown()
  173. t.begin_fill()
  174. t.fd(8)
  175. t.right(90)
  176. t.circle(-4, 180)
  177. t.end_fill()
  178. # 脸
  179. t.penup()
  180. t.width(1)
  181. t.goto(lx, ly)
  182. t.seth(-140)
  183. t.fd(16)
  184. t.seth(-100)
  185. t.color(skin)
  186. t.pendown()
  187. t.begin_fill()
  188. t.circle(-30, 130)
  189. t.left(100)
  190. t.circle(-10, 180)
  191. t.circle(-2, 60)
  192. t.circle(-40, 20)
  193. t.left(150)
  194. t.circle(-10, 90)
  195. t.circle(80, 10)
  196. t.circle(30, 60)
  197. t.right(100)
  198. t.circle(-20, 70)
  199. t.left(3)
  200. t.circle(-200, 9)
  201. t.end_fill()
  202. # 眼睛
  203. t.penup()
  204. t.width(6)
  205. t.goto(lx, ly)
  206. t.color('black')
  207. t.seth(170)
  208. t.fd(25)
  209. t.pendown()
  210. t.seth(120)
  211. t.fd(4)
  212. t.penup()
  213. t.left(90)
  214. t.fd(30)
  215. t.left(90)
  216. t.pendown()
  217. t.fd(4)
  218. # 嘴
  219. t.penup()
  220. t.circle(100, 10)
  221. t.width(4)
  222. t.left(40)
  223. t.color('red')
  224. t.pendown()
  225. t.circle(100, 3)
  226. t.circle(15, 90)
  227. t.circle(100, 3)

824c41110039489e93d6956860e13c07.gif

四、完整代码

  1. import turtle as t
  2. import time
  3. import random as r
  4. import math
  5. skin = '#ffffeb'
  6. def draw_bg():
  7. t.penup()
  8. t.goto(-700, -350)
  9. t.pendown()
  10. t.color((30, 30, 60), (30, 30, 60))
  11. t.begin_fill()
  12. t.goto(700, -350)
  13. t.goto(700, 350)
  14. t.goto(-700, 350)
  15. t.goto(-700, -350)
  16. t.end_fill()
  17. t.penup()
  18. def init_draw():
  19. t.setup(1400, 700, startx=100, starty=100)
  20. t.colormode(255)
  21. # 这样设置背景导出的图片看不到背景
  22. # t.bgcolor(30, 30, 60)
  23. # 画背景
  24. draw_bg()
  25. def draw_moon():
  26. t.penup()
  27. # t.goto(-510, 300)
  28. t.goto(-550, 300)
  29. t.pendown()
  30. t.color('yellow', 'yellow')
  31. t.begin_fill()
  32. # 弯月
  33. # t.right(15)
  34. # t.circle(-60, 220)
  35. # t.right(140)
  36. # t.circle(60, 140)
  37. # 圆月
  38. t.right(15)
  39. t.circle(-100)
  40. t.end_fill()
  41. def draw_star(s):
  42. t.begin_fill()
  43. for _ in range(6):
  44. t.forward(s)
  45. t.right(270)
  46. t.forward(s)
  47. t.right(150)
  48. t.end_fill()
  49. def draw_stars(sn):
  50. for _ in range(sn):
  51. t.penup()
  52. t.goto(r.randint(-500, 600), r.randint(-100, 300))
  53. t.pendown()
  54. c = r.choice(('purple', 'green', 'yellow', 'white', 'blue'))
  55. t.color(c, c)
  56. t.seth(30)
  57. draw_star(r.randint(2, 5))
  58. def draw_mount(d, a):
  59. t.penup()
  60. t.goto(-699-a*d, math.cos(a*(-699+699)/d)*d-100*a)
  61. t.pendown()
  62. t.begin_fill()
  63. for x in range(-700, 1000):
  64. t.goto(x-a*d, math.cos(a*(x+699)/d)*d-100*a)
  65. t.goto(700, -700)
  66. t.goto(-700, -700)
  67. t.goto(-699-a*d, math.cos(a*(-699+699)/d)*d-100*a)
  68. t.end_fill()
  69. def draw_mounts():
  70. t.color('#90EE90', '#90EE90')
  71. draw_mount(80, 1)
  72. t.color('#87CEEB', '#87CEEB')
  73. draw_mount(70, 1.75)
  74. t.color('#7D9EC0', '#7D9EC0')
  75. draw_mount(60, 2.5)
  76. def draw_tree(s, f=5, h=90):
  77. if f == 0:
  78. return
  79. t.pendown()
  80. t.seth(h)
  81. t.fd(s+10 if f==5 else s)
  82. draw_tree(s>>1, f-1, h+45)
  83. t.penup()
  84. t.seth(h+45+180); t.fd(s>>1)
  85. draw_tree(s>>1, f-1, h-45)
  86. t.penup()
  87. t.seth(h-45+180); t.fd(s>>1)
  88. def draw_WuGang():
  89. t.width(2)
  90. # 头
  91. ## 脸
  92. t.penup()
  93. t.goto(-472, 162)
  94. t.seth(70)
  95. t.pendown()
  96. t.color('black')
  97. t.circle(6, 140)
  98. t.color('#b3c518')
  99. t.circle(6, 220)
  100. ## 发髻
  101. t.penup()
  102. t.circle(6, 10)
  103. t.pendown()
  104. t.color('black')
  105. t.begin_fill()
  106. t.circle(-2)
  107. t.end_fill()
  108. ## 眼
  109. t.penup()
  110. t.goto(-478, 165)
  111. t.seth(90)
  112. t.pendown()
  113. t.fd(2)
  114. ## 嘴
  115. t.penup()
  116. t.goto(-481, 161)
  117. t.seth(-30)
  118. t.pendown()
  119. t.color('pink')
  120. t.circle(3, 50)
  121. # 身体
  122. ## 腰
  123. t.penup()
  124. t.color('#386650', '#386650')
  125. t.goto(-482, 143)
  126. t.pendown()
  127. t.seth(-110)
  128. t.fd(12)
  129. t.circle(1, 160)
  130. t.fd(12)
  131. t.right(120)
  132. t.fd(12)
  133. t.circle(1, 160)
  134. t.fd(14)
  135. ## 右肩
  136. t.penup()
  137. t.color('#5cd29b')
  138. t.seth(-1)
  139. t.goto(-475, 158)
  140. t.pendown()
  141. t.circle(-6, 90)
  142. ## 右手
  143. t.fd(3)
  144. t.color(skin)
  145. t.left(149)
  146. t.fd(1)
  147. t.circle(-2, 180)
  148. t.fd(2)
  149. t.circle(-4, 150)
  150. t.color('#4cd29b')
  151. t.fd(3)
  152. # 身体中插入一个斧子 #
  153. ###################
  154. ## 斧子把
  155. t.penup()
  156. t.goto(-486, 143)
  157. t.color('brown')
  158. t.pendown()
  159. t.goto(-456, 152)
  160. ## 斧子头
  161. t.penup()
  162. t.width(1)
  163. t.goto(-458, 148)
  164. t.color('black', 'black')
  165. t.pendown()
  166. t.begin_fill()
  167. t.seth(190)
  168. t.fd(1)
  169. t.right(90)
  170. t.fd(3)
  171. t.circle(8, 60)
  172. t.right(110)
  173. t.circle(-8, 80)
  174. t.right(110)
  175. t.circle(8, 60)
  176. t.fd(4)
  177. t.end_fill()
  178. ###################
  179. ## 左肩
  180. t.penup()
  181. t.width(2)
  182. t.color('#4cd29b')
  183. t.seth(180)
  184. t.goto(-482, 158)
  185. t.pendown()
  186. t.circle(5, 90)
  187. ## 左手
  188. t.fd(5)
  189. t.color(skin)
  190. t.circle(2, 60)
  191. t.fd(4)
  192. t.circle(2, 180)
  193. t.fd(3)
  194. t.color('#5cd29b')
  195. t.circle(-1, 60)
  196. t.fd(3)
  197. def draw_frool(y, j, w, h):
  198. # 房框
  199. t.penup()
  200. t.goto(y, j)
  201. t.pendown()
  202. t.goto(y-w, j)
  203. t.goto(y-w, j+h)
  204. t.goto(y, j+h)
  205. t.goto(y, j)
  206. # 左房檐
  207. t.penup()
  208. t.goto(y-w, j+h)
  209. t.seth(180)
  210. t.pendown()
  211. t.circle(-(int(w/3)), 60)
  212. # 右房檐
  213. t.penup()
  214. t.goto(y, j+h)
  215. t.seth(0)
  216. t.pendown()
  217. t.circle(int(w/3), 60)
  218. # 房门
  219. if y==-480:
  220. t.penup()
  221. t.goto(y-int(w*0.3), j)
  222. t.pendown()
  223. t.goto(y-int(w*0.3), j+int(h/2))
  224. t.goto(y-w+int(w*0.3), j+int(h/2))
  225. t.goto(y-w+int(w*0.3), j)
  226. t.penup()
  227. t.goto(y-int(w*0.5), j+int(h/2))
  228. t.pendown()
  229. t.goto(y-int(w*0.5), j)
  230. t.penup()
  231. t.goto(y-int(w*0.42), j+int(h/4))
  232. t.pendown()
  233. t.circle(0.5)
  234. t.penup()
  235. t.goto(y-int(w*0.58), j+int(h/4))
  236. t.pendown()
  237. t.circle(0.5)
  238. # 画窗户
  239. else:
  240. t.penup()
  241. t.goto(y-int(w*0.2), j+int(h*0.2))
  242. t.pendown()
  243. t.goto(y-w+int(w*0.2), j+int(h*0.2))
  244. t.goto(y-w+int(w*0.2), j+h-int(h*0.2))
  245. t.goto(y-int(w*0.2), j+h-int(h*0.2))
  246. t.goto(y-int(w*0.2), j+int(h*0.2))
  247. t.penup()
  248. t.goto(y-int(w*0.5), j+int(h*0.2))
  249. t.pendown()
  250. t.goto(y-int(w*0.5), j+h-int(h*0.2))
  251. t.penup()
  252. t.goto(y-int(w*0.2), j+int(h*0.5))
  253. t.pendown()
  254. t.goto(y-w+int(w*0.2), j+int(h*0.5))
  255. def draw_palace():
  256. t.color('white')
  257. t.width(4)
  258. draw_frool(-480, 160, 100, 60)
  259. draw_frool(-500, 220, 60, 25)
  260. draw_frool(-510, 245, 40, 20)
  261. draw_frool(-518, 265, 24, 12)
  262. draw_frool(-524, 277, 12, 8)
  263. draw_frool(-528, 285, 4, 2)
  264. def draw_ChangE():
  265. lx, ly = -530, 170
  266. # 左手
  267. t.penup()
  268. t.color(skin)
  269. t.width(4)
  270. t.goto(lx, ly)
  271. t.seth(50)
  272. t.pendown()
  273. t.fd(10)
  274. t.circle(-3, 180)
  275. t.right(170)
  276. t.circle(-6, 180)
  277. t.circle(-50, 20)
  278. # 左袖
  279. t.penup()
  280. t.color('red')
  281. t.goto(lx, ly)
  282. t.seth(-140)
  283. t.pendown()
  284. t.fd(16)
  285. t.penup()
  286. t.goto(lx, ly)
  287. t.seth(-50)
  288. t.pendown()
  289. t.fd(30)
  290. t.right(90)
  291. t.fd(10)
  292. t.circle(-50, 40)
  293. # 衣服
  294. t.color('#f3dd64')
  295. t.penup()
  296. t.right(90)
  297. t.fd(10)
  298. t.right(180)
  299. t.pendown()
  300. t.circle(-100, 8)
  301. t.circle(-20, 80)
  302. t.circle(-100, 11)
  303. # 衣服2
  304. t.penup()
  305. t.circle(-100, -11)
  306. t.circle(-20, -80)
  307. t.fd(8)
  308. t.pendown()
  309. t.circle(-100, 6)
  310. t.circle(-15, 82)
  311. t.circle(-40, 35)
  312. # 衣服-裙
  313. t.color('red')
  314. t.penup()
  315. t.circle(-40, -35)
  316. t.circle(-15, -82)
  317. t.fd(10)
  318. t.right(10)
  319. t.pendown()
  320. t.circle(-100, 60)
  321. t.right(60)
  322. t.circle(-100, 60)
  323. t.right(60)
  324. t.circle(-200, 2)
  325. # 右袖
  326. t.penup()
  327. t.circle(-200, -2)
  328. t.right(-60)
  329. t.circle(-100, -60)
  330. t.right(-60)
  331. t.circle(-100, -60)
  332. t.right(-10)
  333. t.fd(-6)
  334. t.circle(-100, -6)
  335. t.fd(-8)
  336. t.circle(-20, 80)
  337. t.circle(-100, 12)
  338. t.right(110)
  339. t.fd(10)
  340. t.right(180)
  341. t.pendown()
  342. t.circle(-50, 50)
  343. t.right(70)
  344. t.circle(-50, 40)
  345. t.right(57)
  346. t.circle(-200, 10)
  347. # 右手
  348. t.penup()
  349. t.circle(-200, -10)
  350. t.right(-57)
  351. t.circle(-50, -4)
  352. t.color(skin)
  353. t.left(80)
  354. t.circle(10, 15)
  355. t.pendown()
  356. t.circle(10, 190)
  357. # 下方飘带
  358. t.penup()
  359. t.circle(10, -90)
  360. t.seth(-140)
  361. t.color('#f3dd64')
  362. t.circle(-10, 10)
  363. t.pendown()
  364. t.circle(-10, 100)
  365. t.circle(-40, 20)
  366. t.circle(40, 70)
  367. t.left(80)
  368. t.circle(60, 40)
  369. t.left(60)
  370. t.circle(-30, 50)
  371. t.circle(20, 80)
  372. t.fd(25)
  373. # 脸
  374. t.penup()
  375. t.goto(lx, ly)
  376. t.seth(-140)
  377. t.fd(16)
  378. t.seth(-100)
  379. t.color(skin)
  380. t.pendown()
  381. t.circle(-30, 100)
  382. t.color('black')
  383. t.begin_fill()
  384. t.circle(-30, 30)
  385. # 耳朵
  386. t.left(100)
  387. t.circle(-10, 180)
  388. t.circle(-2, 60)
  389. t.circle(-40, 20)
  390. # 头发
  391. t.left(150)
  392. t.circle(-10, 90)
  393. t.circle(80, 10)
  394. t.circle(30, 60)
  395. t.right(100)
  396. t.circle(-20, 70)
  397. t.circle(3, 160)
  398. t.circle(25, 90)
  399. t.left(20)
  400. t.fd(20)
  401. t.right(80)
  402. t.circle(20, 150)
  403. t.right(80)
  404. t.circle(8, 180)
  405. t.right(90)
  406. t.fd(10)
  407. t.right(110)
  408. t.circle(10, 100)
  409. t.right(110)
  410. t.fd(12)
  411. t.circle(8, 110)
  412. t.right(50)
  413. t.circle(12, 70)
  414. t.circle(2, 50)
  415. t.circle(180, 25)
  416. t.end_fill()
  417. # 发髻
  418. t.penup()
  419. t.circle(180, -25)
  420. t.circle(2, -50)
  421. t.circle(12, -70)
  422. t.right(-50)
  423. t.circle(8, -110)
  424. t.fd(-12)
  425. t.right(-110)
  426. t.circle(10, -100)
  427. t.right(-110)
  428. t.fd(-10)
  429. t.right(-90)
  430. t.circle(8, -180)
  431. t.fd(-25)
  432. t.left(20)
  433. t.color('yellow')
  434. t.width(1)
  435. t.pendown()
  436. t.begin_fill()
  437. t.fd(8)
  438. t.right(90)
  439. t.circle(-4, 180)
  440. t.end_fill()
  441. # 脸
  442. t.penup()
  443. t.width(1)
  444. t.goto(lx, ly)
  445. t.seth(-140)
  446. t.fd(16)
  447. t.seth(-100)
  448. t.color(skin)
  449. t.pendown()
  450. t.begin_fill()
  451. t.circle(-30, 130)
  452. t.left(100)
  453. t.circle(-10, 180)
  454. t.circle(-2, 60)
  455. t.circle(-40, 20)
  456. t.left(150)
  457. t.circle(-10, 90)
  458. t.circle(80, 10)
  459. t.circle(30, 60)
  460. t.right(100)
  461. t.circle(-20, 70)
  462. t.left(3)
  463. t.circle(-200, 9)
  464. t.end_fill()
  465. # 眼睛
  466. t.penup()
  467. t.width(6)
  468. t.goto(lx, ly)
  469. t.color('black')
  470. t.seth(170)
  471. t.fd(25)
  472. t.pendown()
  473. t.seth(120)
  474. t.fd(4)
  475. t.penup()
  476. t.left(90)
  477. t.fd(30)
  478. t.left(90)
  479. t.pendown()
  480. t.fd(4)
  481. # 嘴
  482. t.penup()
  483. t.circle(100, 10)
  484. t.width(4)
  485. t.left(40)
  486. t.color('red')
  487. t.pendown()
  488. t.circle(100, 3)
  489. t.circle(15, 90)
  490. t.circle(100, 3)
  491. def add_moon_palace():
  492. # 画月宫
  493. draw_palace()
  494. # 画树
  495. t.penup()
  496. t.color('brown')
  497. t.goto(-500, 110)
  498. t.width(3)
  499. draw_tree(80)
  500. # 画吴刚
  501. draw_WuGang()
  502. # 画嫦娥
  503. draw_ChangE()
  504. def save_draw():
  505. ts = t.getscreen()
  506. ts.getcanvas().postscript(file='o.eps')
  507. if __name__ == '__main__':
  508. t.speed(100)
  509. init_draw()
  510. t.speed(10)
  511. t.speed(40)
  512. draw_stars(30)
  513. t.speed(100)
  514. draw_mounts()
  515. t.speed(10)
  516. draw_moon()
  517. t.speed(100)
  518. add_moon_palace()
  519. t.penup()
  520. t.speed(100)
  521. t.goto(0, -700)
  522. save_draw()
  523. time.sleep(9)
  524. t.mainloop()

#

五、结束语

b9d5e8d02b554f3cb5358b48db658d78.png

大家多多支持,创作不易,祝大家中秋快乐!

希望明年的中秋,初心不变!加油!

往期:

【中秋征文】使用Python中秋节创意图画月饼《花好月圆》

【中秋征文】使用Python中秋节嫦娥投食游戏《千里婵娟》

【中秋征文】使用Python中秋节程序员的浪漫《嫦娥奔月》

发表评论

表情:
评论列表 (有 0 条评论,170人围观)

还没有评论,来说两句吧...

相关阅读

    相关 程序员中秋

    “月圆人团圆,天涯共此时。”对于我们这些在全球各地分布的程序员来说,中秋这个富有诗意的节日,也许并非如诗如画般的浪漫,但却别有一番韵味。在这个特殊的日子里,我想借着这个平台,和

    相关 程序员七夕浪漫时刻

    创意代码表白 要知道女生都是喜欢浪漫的,浪漫不失为一种提升表白成功率的方式。但表白的时候,如果只是一束鲜花,一句简单“我喜欢你”,难免显得太过乏味,而且不够浪漫。那该怎么

    相关 程序员中秋节

    程序员的中秋 八月的夜,有点寒,凄凄的月色透过纱窗,无力地落到床前,淡淡的一片白,又给我带来了一个不眠之夜。明知无人与之同乐,只好由自己的思绪在夜色里游荡。好在白天闲来时

    相关 程序员浪漫

    程序员浪漫表白 艺术系,可以用意境丰富的画作来表达爱意;文学系,可以用文辞优美的文章来传递情话;而程序员呢?大多人以为程序员都是宅男,没有情趣;实则不然,当程序员遇见