当前位置:   article > 正文

你们要的python圣诞树_pycharm圣诞树

pycharm圣诞树

圣诞节要到了,不给对象画一颗圣诞树吗?

那就用python画一颗圣诞树吧

  1. # -*- codeing = utf-8 -*-
  2. # @Time : 2021/12/14 10:35
  3. # @Author : 1
  4. # @File : 圣诞树.py.py
  5. # @Softestr : PyCharm
  6. import turtle
  7. import time
  8. import random
  9. turtle.screensize(700,600, "thistle3")
  10. turtle.pensize(5) # 画笔的粗度
  11. def draw_star():
  12. turtle.pencolor("yellow")
  13. turtle.fillcolor("red") # 选择颜色
  14. turtle.penup() # 抬起
  15. star_x = 25*random.randint(0,10)
  16. star_y = 10*random.randint(0,10)
  17. turtle.goto(280-star_x, 260-star_y)
  18. turtle.pendown() # 按下
  19. turtle.goto(200-star_x, 220-star_y)
  20. turtle.begin_fill()
  21. # 画星星
  22. for _ in range(5):
  23. turtle.forward(10)
  24. turtle.right(144)
  25. turtle.end_fill()
  26. # time.sleep(1)
  27. def langxuan():
  28. # 定义一个函数
  29. for i in range(200): # 设定范围
  30. turtle.right(1)
  31. turtle.forward(1)
  32. turtle.pensize(3) # 设置画笔粗细
  33. turtle.speed(0) # 设置画笔速度 [0-10]之间
  34. turtle.color('pink', 'pink') # 画笔的颜色, 要填充的颜色
  35. turtle.begin_fill() # 准备开始填充图形
  36. turtle.left(140) # 逆时针移动140度
  37. turtle.forward(112) # 当前画笔方向移动112px
  38. langxuan() # 调用函数
  39. turtle.left(120)
  40. langxuan()
  41. turtle.forward(112)
  42. turtle.end_fill() # 填充完成
  43. turtle.goto(0, 90) # 画笔移动到的位置
  44. turtle.color('violet') # 画笔颜色(同时设置字体颜色)
  45. turtle.write('I Love You宝', font=('Arial', 18, 'normal'), align='center', move=True) # 写入内容
  46. for i in range(10):
  47. draw_star()
  48. turtle.penup()
  49. turtle.goto(60, 80)
  50. turtle.color("violet")
  51. # turtle.write("hyx", font=('Arial', 40, 'normal'))
  52. turtle.goto(0, -10)
  53. turtle.left(140)
  54. # 定义圣诞树的绿叶函数
  55. def tree(d, s):
  56. if d <= 0:
  57. return
  58. turtle.forward(s)
  59. tree(d - 1, s * .8)
  60. turtle.right(120)
  61. tree(d - 3, s * .5)
  62. turtle.right(120)
  63. tree(d - 3, s * .5)
  64. turtle.right(120)
  65. turtle.backward(s)
  66. # 画文字
  67. turtle.penup()
  68. turtle.forward(100)
  69. turtle.write('祝你天天开心丫',font=('Colonna MT',15,'bold'))
  70. turtle.left(90)
  71. turtle.forward(20)
  72. turtle.write('给陈佳希画颗圣诞树',font=('Colonna MT',15,'bold'))
  73. turtle.right(90)
  74. turtle.left(180)
  75. turtle.forward(400)
  76. turtle.write('祝你圣诞快乐',font=('Colonna MT',20,'bold'))
  77. turtle.left(180)
  78. turtle.forward(300)
  79. turtle.right(90)
  80. turtle.forward(40)
  81. turtle.left(90)
  82. turtle.pendown()
  83. n = 90
  84. """ 设置绘图速度
  85. 'fastest' : 0
  86. 'fast' : 10
  87. 'normal' : 6
  88. 'slow' : 3
  89. 'slowest' : 1
  90. """
  91. turtle.speed('fastest') # 设置速度
  92. turtle.left(90)
  93. turtle.forward(3 * n)
  94. turtle.color("orange", "yellow")
  95. turtle.left(126)
  96. # turtle.begin_fill()
  97. for i in range(5):
  98. turtle.forward(n / 5)
  99. turtle.right(144)
  100. turtle.forward(n / 5)
  101. turtle.left(72)
  102. turtle.end_fill()
  103. turtle.right(126)
  104. turtle.color("dark green")
  105. turtle.backward(n * 4.8)
  106. # 执行函数
  107. tree(15, n)
  108. turtle.backward(n / 5)
  109. for i in range(200):
  110. a = 200 - 400 * random.random()
  111. b = 10 - 20 * random.random()
  112. turtle.up()
  113. turtle.forward(b)
  114. turtle.left(90)
  115. turtle.forward(a)
  116. turtle.down()
  117. if random.randint(0, 1) == 0:
  118. turtle.color('tomato')
  119. else:
  120. turtle.color('wheat')
  121. turtle.circle(2)
  122. turtle.up()
  123. turtle.backward(a)
  124. turtle.right(90)
  125. turtle.backward(b)
  126. turtle.mainloop()

上效果图

 大家通过其,用自己创意修该,给对象一个惊喜吧!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/325878
推荐阅读
相关标签
  

闽ICP备14008679号