python turtle画玉米
时间: 2023-08-28 16:04:33 浏览: 149
python用turtle画画
下面是使用Python Turtle模块画玉米的示例代码:
```python
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 设置画笔颜色和画笔大小
turtle.color("green")
turtle.pensize(3)
# 画玉米叶子
turtle.begin_fill()
turtle.left(45)
turtle.forward(150)
turtle.right(135)
turtle.forward(150)
turtle.right(135)
turtle.forward(150)
turtle.right(135)
turtle.forward(150)
turtle.end_fill()
# 画玉米芯
turtle.color("yellow")
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
# 画玉米粒
turtle.penup()
turtle.goto(0, 50)
turtle.pendown()
turtle.color("brown")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(20, 80)
turtle.pendown()
turtle.color("brown")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(-20, 80)
turtle.pendown()
turtle.color("brown")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(0, 110)
turtle.pendown()
turtle.color("brown")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
运行上述代码,可以看到绘制出一个玉米的图形。你也可以根据自己的需求更改代码中的参数,例如改变画布大小、画笔颜色、画笔大小等。
阅读全文