当前位置:   article > 正文

python画科赫雪花_python绘制科赫雪花代码

python绘制科赫雪花代码

  1. import turtle as t
  2. from turtle import *
  3. import random
  4. def draw_path(path):
  5. t.colormode(255)
  6. t.color(random.randint(0,255),random.randint(0,255),random.randint(0,255))
  7. for symbol in path:
  8. if symbol == 'F':
  9. forward(length)
  10. elif symbol == '-':
  11. right(angle)
  12. elif symbol == '+':
  13. left(angle)
  14. def apply_rule(path):
  15. rule = 'F+F--F+F'
  16. return path.replace('F',rule)
  17. length = .5
  18. angle = 60
  19. setup(1280,720)
  20. bgcolor('black')
  21. up()
  22. color("#0fe6ca")
  23. goto(0,0)
  24. down()
  25. path = 'F--F--F'
  26. speed(0)
  27. up()
  28. goto(-440,-250)
  29. down()
  30. for i in range(5):
  31. path = apply_rule(path)
  32. draw_path(path)
  33. draw_path(path)
  34. draw_path(path)
  35. a,b = pos()
  36. for i in range(3):
  37. up()
  38. a += 250
  39. goto(a,b)
  40. down()
  41. draw_path(path)
  42. draw_path(path)
  43. draw_path(path)
  44. b += 220
  45. for i in range(2):
  46. up()
  47. a -= 250
  48. goto(a,b)
  49. down()
  50. draw_path(path)
  51. draw_path(path)
  52. draw_path(path)
  53. b += 220
  54. for i in range(2):
  55. draw_path(path)
  56. draw_path(path)
  57. draw_path(path)
  58. up()
  59. a += 130
  60. goto(a,b)
  61. down()

运行结果

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

闽ICP备14008679号