python 绘制红色的玫瑰花
时间: 2023-06-29 22:17:14 浏览: 84
python绘制玫瑰
5星 · 资源好评率100%
以下是使用Python的Turtle库绘制一朵红色的玫瑰花的示例代码:
```python
import turtle
# 设置画布和画笔
canvas = turtle.Screen()
canvas.bgcolor("black")
pen = turtle.Turtle()
pen.speed(0)
pen.color("red")
# 绘制花朵
for i in range(10):
pen.circle(100)
pen.right(36)
# 绘制花瓣
for i in range(12):
pen.penup()
pen.setposition(0, 0)
pen.pendown()
pen.left(i * 30)
pen.forward(150)
pen.right(90)
pen.begin_fill()
pen.circle(20, 180)
pen.left(90)
pen.circle(20, 180)
pen.end_fill()
# 绘制花蕾
pen.penup()
pen.setposition(0, 0)
pen.pendown()
pen.color("green")
pen.begin_fill()
pen.circle(50)
pen.end_fill()
# 隐藏画笔
pen.hideturtle()
# 关闭画布
canvas.exitonclick()
```
运行上述代码,将会绘制出一朵红色的玫瑰花。你可以根据自己的喜好调整花朵和花瓣的颜色和大小。
阅读全文