python清明上河图代码
时间: 2023-10-12 15:58:30 浏览: 538
以下是一个使用Python绘制清明上河图的代码示例:
```python
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 定义绘制河流的函数
def draw_river():
turtle.penup()
turtle.goto(-400, -200)
turtle.pendown()
turtle.color('blue')
turtle.fillcolor('blue')
turtle.begin_fill()
turtle.forward(800)
turtle.left(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(800)
turtle.left(90)
turtle.forward(50)
turtle.end_fill()
# 定义绘制桥的函数
def draw_bridge():
turtle.penup()
turtle.goto(-400, -150)
turtle.pendown()
turtle.color('brown')
turtle.fillcolor('brown')
turtle.begin_fill()
turtle.forward(800)
turtle.right(90)
turtle.forward(20)
turtle.right(90)
turtle.forward(800)
turtle.right(90)
turtle.forward(20)
turtle.end_fill()
# 定义绘制人物的函数
def draw_people():
turtle.penup()
turtle.goto(-200, -150)
turtle.pendown()
turtle.color('black')
turtle.fillcolor('black')
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(-220, -150)
turtle.pendown()
turtle.color('black')
turtle.fillcolor('black')
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(-240, -150)
turtle.pendown()
turtle.color('black')
turtle.fillcolor('black')
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(-260, -150)
turtle.pendown()
turtle.color('black')
turtle.fillcolor('black')
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 绘制清明上河图
draw_river()
draw_bridge()
draw_people()
# 点击窗口关闭程序
turtle.exitonclick()
```
这段代码使用了Python的turtle库来绘制清明上河图。首先定义了绘制河流、桥和人物的函数,然后在主程序中调用这些函数来完成绘制。最后使用`turtle.exitonclick()`函数来实现点击窗口关闭程序的功能。
#### 引用[.reference_title]
- *1* *2* *3* [一日一技:用Python绘画有多好玩](https://blog.csdn.net/m0_59485658/article/details/125589128)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文