python turtle画玉米
时间: 2023-08-29 09:10:52 浏览: 127
使用Python的turtle模块画图
以下是用 Python Turtle 画玉米的代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor("lightgreen")
# 定义画笔的属性
turtle.pensize(3)
turtle.pencolor("brown")
turtle.fillcolor("yellow")
# 画出玉米的形状
turtle.begin_fill()
turtle.forward(100)
turtle.right(45)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(45)
turtle.forward(100)
turtle.right(135)
turtle.forward(70)
turtle.right(135)
turtle.forward(100)
turtle.right(45)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(45)
turtle.forward(100)
turtle.end_fill()
# 画出玉米的叶子
turtle.penup()
turtle.goto(-50, 60)
turtle.pendown()
turtle.begin_fill()
turtle.goto(-100, 120)
turtle.goto(-70, 140)
turtle.goto(-20, 80)
turtle.goto(-50, 60)
turtle.end_fill()
turtle.penup()
turtle.goto(50, 60)
turtle.pendown()
turtle.begin_fill()
turtle.goto(100, 120)
turtle.goto(70, 140)
turtle.goto(20, 80)
turtle.goto(50, 60)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 显示绘制结果
turtle.done()
```
运行以上代码,即可在 Turtle 画布上绘出一个玉米的图案。
阅读全文