python玫瑰原代码
时间: 2023-12-08 11:39:42 浏览: 63
根据提供的引用内容,以下是Python用turtle库绘制玫瑰的原代码:
```python
import turtle as t
import time
# 绘制花瓣
def huaban(radius, angle):
t.circle(radius, angle)
t.left(180 - angle)
t.circle(radius, angle)
t.left(180 - angle)
# 绘制花朵
def flower(radius, angle, num):
for i in range(num):
huaban(radius, angle)
t.left(360 / num)
# 绘制叶子
def leaf(radius, angle):
t.circle(-radius, angle)
t.left(180 - angle)
t.circle(-radius, angle)
t.left(180 - angle)
# 绘制花梗
def stem(height):
t.pensize(4)
t.right(90)
t.forward(height)
# 绘制花萼
def sepal(radius, angle):
t.pensize(2)
t.color('green')
t.circle(radius, angle)
t.left(180 - angle)
t.circle(radius, angle)
t.left(180 - angle)
# 绘制玫瑰
def rose():
t.speed(0)
t.color('red', 'pink')
t.begin_fill()
flower(100, 60, 6)
t.end_fill()
t.color('green')
stem(200)
t.color('dark green')
t.right(90)
leaf(80, 60)
t.right(120)
leaf(80, 60)
t.right(120)
leaf(80, 60)
t.right(30)
sepal(80, 60)
t.right(120)
sepal(80, 60)
t.right(120)
sepal(80, 60)
t.hideturtle()
# 主函数
if __name__ == '__main__':
rose()
time.sleep(5)
```
阅读全文