python tirtle绘制一块麦田,有房子,太阳,云,小树,
时间: 2024-02-03 20:10:36 浏览: 84
好的,这里给你提供一个绘制麦田、房子、太阳、云、小树的Python Turtle代码示例,你可以根据需要进行修改:
```python
import turtle
# 创建窗口和画布
window = turtle.Screen()
canvas = turtle.Turtle()
# 麦田
canvas.penup()
canvas.goto(-200, -200)
canvas.pendown()
canvas.begin_fill()
canvas.fillcolor('#B2B200')
canvas.forward(400)
canvas.right(90)
canvas.forward(300)
canvas.right(90)
canvas.forward(400)
canvas.right(90)
canvas.forward(300)
canvas.end_fill()
# 房子
canvas.penup()
canvas.goto(-150, -100)
canvas.pendown()
canvas.begin_fill()
canvas.fillcolor('brown')
canvas.forward(100)
canvas.right(90)
canvas.forward(100)
canvas.right(90)
canvas.forward(100)
canvas.right(90)
canvas.forward(100)
canvas.end_fill()
canvas.penup()
canvas.goto(-150, 0)
canvas.pendown()
canvas.begin_fill()
canvas.fillcolor('red')
canvas.forward(100)
canvas.right(120)
canvas.forward(100)
canvas.right(120)
canvas.forward(100)
canvas.end_fill()
# 太阳
canvas.penup()
canvas.goto(150, 150)
canvas.pendown()
canvas.begin_fill()
canvas.fillcolor('yellow')
canvas.circle(50)
canvas.end_fill()
# 云
canvas.penup()
canvas.goto(-100, 150)
canvas.pendown()
canvas.begin_fill()
canvas.fillcolor('white')
canvas.circle(30)
canvas.penup()
canvas.goto(-70, 150)
canvas.pendown()
canvas.circle(30)
canvas.penup()
canvas.goto(-40, 150)
canvas.pendown()
canvas.circle(30)
canvas.end_fill()
# 小树
canvas.penup()
canvas.goto(50, -200)
canvas.pendown()
canvas.begin_fill()
canvas.fillcolor('brown')
canvas.forward(20)
canvas.right(90)
canvas.forward(50)
canvas.right(90)
canvas.forward(20)
canvas.right(90)
canvas.forward(50)
canvas.end_fill()
canvas.penup()
canvas.goto(30, -150)
canvas.pendown()
canvas.begin_fill()
canvas.fillcolor('green')
canvas.circle(30)
canvas.end_fill()
# 隐藏画笔
canvas.hideturtle()
# 保持窗口一直显示
window.mainloop()
```
这段代码绘制了一个麦田、一个房子、一个太阳、一个云和一个小树。你可以在代码中看到调用了不同的方法来实现绘制不同的形状和填充颜色。
阅读全文