python用turtle库画彩色箭靶
时间: 2023-06-30 16:12:44 浏览: 160
好的,下面是使用Python的turtle库画彩色箭靶的代码:
```python
import turtle
# 设置画布
turtle.setup(800, 800)
# 定义画笔
pen = turtle.Turtle()
# 画第一环
pen.penup()
pen.goto(0, -200)
pen.pendown()
pen.begin_fill()
pen.color('red')
pen.circle(200)
pen.end_fill()
# 画第二环
pen.penup()
pen.goto(0, -150)
pen.pendown()
pen.begin_fill()
pen.color('white')
pen.circle(150)
pen.end_fill()
# 画第三环
pen.penup()
pen.goto(0, -100)
pen.pendown()
pen.begin_fill()
pen.color('red')
pen.circle(100)
pen.end_fill()
# 画第四环
pen.penup()
pen.goto(0, -50)
pen.pendown()
pen.begin_fill()
pen.color('white')
pen.circle(50)
pen.end_fill()
# 画箭头
pen.penup()
pen.goto(0, 0)
pen.pendown()
pen.pensize(5)
pen.color('blue')
pen.goto(0, 200)
pen.goto(-50, 170)
pen.goto(0, 200)
pen.goto(50, 170)
# 隐藏画笔
pen.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
运行以上代码,你可以得到一个彩色箭靶的图形。
阅读全文