用python turtle 画天津天塔
时间: 2023-10-22 16:05:24 浏览: 100
以下是使用Python的turtle库画天津之眼的示例代码:
```python
import turtle
# 创建画布
canvas = turtle.Screen()
canvas.bgcolor("white")
# 创建画笔
pen = turtle.Turtle()
pen.speed(5)
pen.color("red")
pen.pensize(3)
# 绘制天塔
pen.penup()
pen.goto(-100, 0)
pen.pendown()
pen.circle(100)
# 绘制塔尖
pen.penup()
pen.goto(-50, 100)
pen.pendown()
pen.goto(0, 200)
pen.goto(50, 100)
# 绘制塔身
pen.penup()
pen.goto(-120, -150)
pen.pendown()
pen.goto(120, -150)
pen.goto(120, -50)
pen.goto(-120, -50)
pen.goto(-120, -150)
# 绘制支架
pen.penup()
pen.goto(-30, -150)
pen.pendown()
pen.goto(-30, 0)
pen.penup()
pen.goto(30, -150)
pen.pendown()
pen.goto(30, 0)
# 隐藏画笔
pen.hideturtle()
# 点击关闭窗口
canvas.exitonclick()
```
以上代码将绘制一个红色的天塔,包括塔尖、塔身和支架。你可以根据需要更改颜色、位置和大小等参数来自定义绘制的天塔。
阅读全文