用python画一朵玫瑰花
时间: 2023-10-23 09:12:08 浏览: 137
python绘制玫瑰
5星 · 资源好评率100%
以下是使用turtle库绘制一朵玫瑰花的Python代码:
```python
import turtle
# 设置画布和画笔
canvas = turtle.Screen()
pen = turtle.Turtle()
# 设置画笔的颜色和粗细
pen.color("red")
pen.pensize(2)
# 绘制玫瑰花的轮廓
pen.up()
pen.goto(0, 200)
pen.down()
pen.begin_fill()
pen.fillcolor("pink")
for i in range(200):
pen.right(1)
pen.forward(0.3)
pen.end_fill()
# 绘制玫瑰花的花瓣
for i in range(10):
pen.up()
pen.goto(0, 0)
pen.setheading(0)
pen.down()
pen.begin_fill()
pen.fillcolor("red")
for j in range(50):
pen.right(1)
pen.forward(2)
pen.left(120)
for j in range(50):
pen.right(1)
pen.forward(2)
pen.left(120)
for j in range(50):
pen.right(1)
pen.forward(2)
pen.end_fill()
# 隐藏画笔
pen.hideturtle()
# 显示绘制结果
canvas.mainloop()
```
该代码运行后将绘制一朵粉色的玫瑰花,花瓣为红色。可以根据需要调整颜色、粗细或其他参数来自定义绘制结果。
阅读全文