python用turtle画郁金香
时间: 2024-06-04 21:05:15 浏览: 185
要使用turtle画出郁金香,可以按照以下步骤进行:
1. 导入turtle库
```
import turtle
```
2. 设置画布和画笔属性
```
wn = turtle.Screen()
wn.bgcolor("lightblue")
tulip = turtle.Turtle()
tulip.color("purple")
tulip.fillcolor("pink")
tulip.pensize(5)
tulip.speed(2)
```
3. 画出郁金香的花瓣
```
tulip.penup()
tulip.goto(0,0)
tulip.pendown()
tulip.begin_fill()
tulip.right(45)
tulip.forward(100)
tulip.right(135)
tulip.forward(100)
tulip.right(45)
tulip.forward(100)
tulip.right(135)
tulip.forward(100)
tulip.end_fill()
```
4. 画出郁金香的茎和叶子
```
tulip.left(135)
tulip.penup()
tulip.goto(0,-100)
tulip.pendown()
tulip.color("green")
tulip.pensize(10)
tulip.right(90)
tulip.forward(200)
tulip.right(180)
tulip.forward(100)
tulip.right(90)
tulip.forward(100)
```
5. 关闭画布
```
wn.exitonclick()
```
以下是完整的代码:
```
import turtle
# 设置画布
wn = turtle.Screen()
wn.bgcolor("lightblue")
# 设置画笔属性
tulip = turtle.Turtle()
tulip.color("purple")
tulip.fillcolor("pink")
tulip.pensize(5)
tulip.speed(2)
# 画花瓣
tulip.penup()
tulip.goto(0,0)
tulip.pendown()
tulip.begin_fill()
tulip.right(45)
tulip.forward(100)
tulip.right(135)
tulip.forward(100)
tulip.right(45)
tulip.forward(100)
tulip.right(135)
tulip.forward(100)
tulip.end_fill()
# 画茎和叶子
tulip.left(135)
tulip.penup()
tulip.goto(0,-100)
tulip.pendown()
tulip.color("green")
tulip.pensize(10)
tulip.right(90)
tulip.forward(200)
tulip.right(180)
tulip.forward(100)
tulip.right(90)
tulip.forward(100)
# 关闭画布
wn.exitonclick()
```
阅读全文
相关推荐















