用pytuon帮我写一个玫瑰花代码
时间: 2024-01-29 11:02:30 浏览: 69
以下是一个简单的Python玫瑰花代码:
```python
import turtle
def draw_petal(turtle, radius):
turtle.circle(radius, 60)
turtle.left(120)
turtle.circle(radius, 60)
def draw_flower(turtle, petal_radius, petal_num):
for i in range(petal_num):
draw_petal(turtle, petal_radius)
turtle.left(360 / petal_num)
def draw_stem(turtle, stem_length):
turtle.right(90)
turtle.forward(stem_length)
def draw_leaf(turtle, leaf_size):
turtle.right(90)
turtle.forward(leaf_size)
turtle.right(120)
turtle.forward(leaf_size)
turtle.right(120)
turtle.forward(leaf_size)
turtle.right(180)
turtle.forward(leaf_size)
turtle.right(60)
turtle.forward(leaf_size)
turtle.right(60)
def draw_rose(turtle, petal_radius, petal_num, stem_length, leaf_size):
draw_flower(turtle, petal_radius, petal_num)
draw_stem(turtle, stem_length)
draw_leaf(turtle, leaf_size)
if __name__ == '__main__':
window = turtle.Screen()
window.bgcolor("white")
window.title("Rose")
rose = turtle.Turtle()
rose.color("red")
rose.speed(10)
rose.penup()
rose.goto(0, -150)
rose.pendown()
draw_rose(rose, 100, 12, 200, 50)
window.exitonclick()
```
可以根据需要调整玫瑰花的大小和形状。
阅读全文