用turtle 画出蜘蛛
时间: 2023-09-28 08:05:25 浏览: 119
好的,以下是用Python的turtle库画出蜘蛛的代码:
```python
import turtle
# 设置画布大小
turtle.setup(500, 500)
# 画蜘蛛头
turtle.pencolor("black")
turtle.fillcolor("black")
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
# 画蜘蛛身体
turtle.penup()
turtle.goto(0, -50)
turtle.pendown()
turtle.pencolor("black")
turtle.fillcolor("black")
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
# 画蜘蛛的八只腿
turtle.penup()
turtle.goto(20, -80)
turtle.pendown()
turtle.pencolor("black")
turtle.setheading(180)
turtle.circle(20, 180)
turtle.circle(-20, 180)
turtle.penup()
turtle.goto(-20, -80)
turtle.pendown()
turtle.pencolor("black")
turtle.setheading(0)
turtle.circle(-20, 180)
turtle.circle(20, 180)
turtle.penup()
turtle.goto(35, -80)
turtle.pendown()
turtle.pencolor("black")
turtle.setheading(225)
turtle.forward(40)
turtle.penup()
turtle.goto(-35, -80)
turtle.pendown()
turtle.pencolor("black")
turtle.setheading(315)
turtle.forward(40)
# 隐藏画笔
turtle.hideturtle()
# 程序结束,窗口不关闭
turtle.done()
```
运行代码后,就可以看到画出的蜘蛛啦!
阅读全文