画一个向日葵 python
时间: 2023-10-29 11:04:42 浏览: 257
python向日葵代码.docx
以下是一段使用turtle库在Python中绘制向日葵的代码:
```python
import turtle
# 设置画布大小和背景色
turtle.setup(800, 600)
turtle.bgcolor("lightblue")
# 绘制向日葵的花盘
turtle.speed(0)
turtle.penup()
turtle.goto(0, -250)
turtle.pendown()
turtle.fillcolor("yellow")
turtle.begin_fill()
turtle.circle(250)
turtle.end_fill()
# 绘制向日葵的花瓣
turtle.pensize(10)
colors = ["#FF8000", "#FFA500", "#FFC200", "#FFD700", "#FFFF00"]
for i in range(20):
turtle.pencolor(colors[i % len(colors)])
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.right(i*18)
turtle.forward(200)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(200)
turtle.right(90)
turtle.forward(50)
# 隐藏画笔
turtle.hideturtle()
turtle.done()
```
运行代码后,即可在画布上看到绘制的向日葵。
阅读全文