python用turtle画足球场
时间: 2023-12-25 19:29:25 浏览: 121
以下是使用Python的turtle模块绘制足球场的示例代码:
```python
import turtle
# 创建画布
canvas = turtle.Screen()
canvas.title("Football Field")
canvas.bgcolor("green")
# 创建画笔
pen = turtle.Turtle()
pen.color("white")
pen.speed(0)
pen.penup()
# 绘制足球场边界
pen.goto(-250, -150)
pen.pendown()
pen.goto(-250, 150)
pen.goto(250, 150)
pen.goto(250, -150)
pen.goto(-250, -150)
pen.penup()
# 绘制中线
pen.goto(0, -150)
pen.pendown()
pen.goto(0, 150)
pen.penup()
# 绘制中圈
pen.goto(0, 0)
pen.pendown()
pen.circle(9)
pen.penup()
# 绘制球门
pen.goto(-250, 50)
pen.pendown()
pen.goto(-220, 50)
pen.goto(-220, -50)
pen.goto(-250, -50)
pen.penup()
pen.goto(250, 50)
pen.pendown()
pen.goto(220, 50)
pen.goto(220, -50)
pen.goto(250, -50)
pen.penup()
# 绘制角球区
pen.goto(-250, 100)
pen.pendown()
pen.goto(-230, 100)
pen.goto(-230, -100)
pen.goto(-250, -100)
pen.penup()
pen.goto(250, 100)
pen.pendown()
pen.goto(230, 100)
pen.goto(230, -100)
pen.goto(250, -100)
pen.penup()
# 隐藏画笔
pen.hideturtle()
# 关闭画布
turtle.done()
```
阅读全文