用turtle画江南水乡
时间: 2023-06-11 16:08:17 浏览: 137
Python 标准库turtle
好的,以下是用turtle画江南水乡的代码:
```python
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 设置画笔大小和颜色
turtle.pensize(2)
turtle.pencolor('black')
# 绘制江南水乡的河流
turtle.penup()
turtle.goto(-400, 0)
turtle.pendown()
turtle.seth(0)
turtle.fillcolor('lightblue')
turtle.begin_fill()
turtle.fd(800)
turtle.right(90)
turtle.fd(150)
turtle.right(90)
turtle.fd(800)
turtle.right(90)
turtle.fd(150)
turtle.end_fill()
# 绘制江南水乡的房屋
turtle.penup()
turtle.goto(-350, -50)
turtle.pendown()
turtle.seth(0)
turtle.fillcolor('white')
turtle.begin_fill()
turtle.fd(100)
turtle.right(90)
turtle.fd(100)
turtle.right(90)
turtle.fd(100)
turtle.right(90)
turtle.fd(100)
turtle.end_fill()
turtle.penup()
turtle.goto(-200, -50)
turtle.pendown()
turtle.seth(0)
turtle.fillcolor('white')
turtle.begin_fill()
turtle.fd(100)
turtle.right(90)
turtle.fd(150)
turtle.right(90)
turtle.fd(100)
turtle.right(90)
turtle.fd(150)
turtle.end_fill()
turtle.penup()
turtle.goto(50, -50)
turtle.pendown()
turtle.seth(0)
turtle.fillcolor('white')
turtle.begin_fill()
turtle.fd(100)
turtle.right(90)
turtle.fd(50)
turtle.right(90)
turtle.fd(100)
turtle.right(90)
turtle.fd(50)
turtle.end_fill()
# 绘制江南水乡的树木
turtle.penup()
turtle.goto(-300, -50)
turtle.pendown()
turtle.seth(0)
turtle.fillcolor('green')
turtle.begin_fill()
turtle.fd(50)
turtle.right(120)
turtle.fd(50)
turtle.right(120)
turtle.fd(50)
turtle.end_fill()
turtle.penup()
turtle.goto(-100, -50)
turtle.pendown()
turtle.seth(0)
turtle.fillcolor('green')
turtle.begin_fill()
turtle.fd(50)
turtle.right(120)
turtle.fd(50)
turtle.right(120)
turtle.fd(50)
turtle.end_fill()
turtle.penup()
turtle.goto(150, -50)
turtle.pendown()
turtle.seth(0)
turtle.fillcolor('green')
turtle.begin_fill()
turtle.fd(50)
turtle.right(120)
turtle.fd(50)
turtle.right(120)
turtle.fd(50)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 保持窗口不关闭
turtle.done()
```
运行代码后,会在窗口中绘制出一个简单的江南水乡的场景,包括河流、房屋和树木。你可以根据自己的需求进行修改和美化。
阅读全文