turtle绘制乡村风景图
时间: 2023-09-10 22:15:13 浏览: 134
turtle作图作品
好的,以下是使用Python的turtle库绘制乡村风景图的代码示例:
```python
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 设置画笔颜色
turtle.color('green')
# 绘制草地
turtle.begin_fill()
turtle.fillcolor('green')
turtle.goto(-400, -300)
turtle.goto(400, -300)
turtle.goto(400, -100)
turtle.goto(-400, -100)
turtle.goto(-400, -300)
turtle.end_fill()
# 绘制天空
turtle.begin_fill()
turtle.fillcolor('lightblue')
turtle.goto(-400, -100)
turtle.goto(400, -100)
turtle.goto(400, 300)
turtle.goto(-400, 300)
turtle.goto(-400, -100)
turtle.end_fill()
# 绘制太阳
turtle.penup()
turtle.goto(-300, 200)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor('yellow')
turtle.circle(50)
turtle.end_fill()
# 绘制小房子
turtle.penup()
turtle.goto(-200, -100)
turtle.pendown()
turtle.color('brown')
turtle.begin_fill()
turtle.fillcolor('brown')
turtle.goto(-100, -100)
turtle.goto(-100, 0)
turtle.goto(-200, 0)
turtle.goto(-200, -100)
turtle.end_fill()
# 绘制房顶
turtle.penup()
turtle.goto(-200, 0)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor('red')
turtle.goto(-100, 100)
turtle.goto(0, 0)
turtle.goto(-200, 0)
turtle.end_fill()
# 绘制树
turtle.penup()
turtle.goto(200, -100)
turtle.pendown()
turtle.color('brown')
turtle.begin_fill()
turtle.fillcolor('brown')
turtle.goto(250, -100)
turtle.goto(250, 0)
turtle.goto(200, 0)
turtle.goto(200, -100)
turtle.end_fill()
turtle.penup()
turtle.goto(225, 0)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor('darkgreen')
turtle.circle(25)
turtle.end_fill()
turtle.penup()
turtle.goto(175, 25)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor('darkgreen')
turtle.circle(25)
turtle.end_fill()
turtle.penup()
turtle.goto(225, 50)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor('darkgreen')
turtle.circle(25)
turtle.end_fill()
turtle.penup()
turtle.goto(175, 75)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor('darkgreen')
turtle.circle(25)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
运行以上代码,即可在窗口中看到绘制的乡村风景图。你也可以根据自己的需求进行修改和扩展。
阅读全文