当前位置:   article > 正文

基于Python的Turtle库实现玫瑰花的绘制_spyder如何运行python 玫瑰代码

spyder如何运行python 玫瑰代码

说明:

  1.  本文运行环境:Anaconda3+Spyder4+python3.8
  2. 依赖库:turtle
  3. 打开Anaconda Prompt,输入以下命令下载安装turtle库
pip install turtle

安装好后,可以在Anaconda Prompt输入以下命令查看turtle库的相关信息

pip show turtle

打开spyder,新建文件,输入以下代码,点击运行即可

  1. # -*- coding: utf-8 -*-
  2. import turtle
  3. # 设置初始位置
  4. turtle.penup()
  5. turtle.left(90)
  6. turtle.fd(200)
  7. turtle.pendown()
  8. turtle.right(90)
  9. # 花蕊
  10. turtle.fillcolor("red")
  11. turtle.begin_fill()
  12. turtle.circle(10, 180)
  13. turtle.circle(25, 110)
  14. turtle.left(50)
  15. turtle.circle(60, 45)
  16. turtle.circle(20, 170)
  17. turtle.right(24)
  18. turtle.fd(30)
  19. turtle.left(10)
  20. turtle.circle(30, 110)
  21. turtle.fd(20)
  22. turtle.left(40)
  23. turtle.circle(90, 70)
  24. turtle.circle(30, 150)
  25. turtle.right(30)
  26. turtle.fd(15)
  27. turtle.circle(80, 90)
  28. turtle.left(15)
  29. turtle.fd(45)
  30. turtle.right(165)
  31. turtle.fd(20)
  32. turtle.left(155)
  33. turtle.circle(150, 80)
  34. turtle.left(50)
  35. turtle.circle(150, 90)
  36. turtle.end_fill()
  37. # 花瓣1
  38. turtle.left(150)
  39. turtle.circle(-90, 70)
  40. turtle.left(20)
  41. turtle.circle(75, 105)
  42. turtle.setheading(60)
  43. turtle.circle(80, 98)
  44. turtle.circle(-90, 40)
  45. # 花瓣2
  46. turtle.left(180)
  47. turtle.circle(90, 40)
  48. turtle.circle(-80, 98)
  49. turtle.setheading(-83)
  50. # 叶子1
  51. turtle.fd(30)
  52. turtle.left(90)
  53. turtle.fd(25)
  54. turtle.left(45)
  55. turtle.fillcolor("green")
  56. turtle.begin_fill()
  57. turtle.circle(-80, 90)
  58. turtle.right(90)
  59. turtle.circle(-80, 90)
  60. turtle.end_fill()
  61. turtle.right(135)
  62. turtle.fd(60)
  63. turtle.left(180)
  64. turtle.fd(85)
  65. turtle.left(90)
  66. turtle.fd(80)
  67. # 叶子2
  68. turtle.right(90)
  69. turtle.right(45)
  70. turtle.fillcolor("green")
  71. turtle.begin_fill()
  72. turtle.circle(80, 90)
  73. turtle.left(90)
  74. turtle.circle(80, 90)
  75. turtle.end_fill()
  76. turtle.left(135)
  77. turtle.fd(60)
  78. turtle.left(180)
  79. turtle.fd(60)
  80. turtle.right(90)
  81. turtle.circle(200, 60)
  82. turtle.pendown()
  83. turtle.done()

运行结果如下图所示

 

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

闽ICP备14008679号