python代码画动态向日葵
时间: 2023-12-25 07:29:42 浏览: 101
python向日葵代码.docx
以下是使用Python的turtle模块绘制动态向日葵的代码示例:
```python
import turtle
# 设置画布和画笔
canvas = turtle.Screen()
canvas.bgcolor("white")
pen = turtle.Turtle()
pen.speed(10)
# 绘制向日葵的花瓣
def draw_sunflower():
for _ in range(36):
pen.forward(100)
pen.right(45)
pen.forward(100)
pen.right(135)
pen.forward(100)
pen.right(45)
pen.forward(100)
pen.right(135)
pen.right(10)
# 绘制向日葵的花盘
def draw_sunflower_center():
pen.color("brown")
pen.begin_fill()
pen.circle(20)
pen.end_fill()
# 绘制向日葵的茎和叶子
def draw_stem_and_leaves():
pen.penup()
pen.goto(0, -200)
pen.pendown()
pen.color("green")
pen.right(90)
pen.forward(200)
pen.right(90)
pen.forward(20)
pen.right(90)
pen.forward(200)
pen.right(90)
pen.forward(20)
pen.right(180)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen.right(90)
pen.forward(100)
pen.right(180)
pen.forward(100)
pen.right(90)
pen.forward(40)
pen
阅读全文