用Python turtle库绘出一个海绵宝宝。
时间: 2023-11-05 15:44:26 浏览: 147
AI用进化算法画出海绵宝宝_python_代码_下载
当然可以!下面是使用Python的turtle库绘制海绵宝宝的代码:
```python
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 创建海绵宝宝的头部
head = turtle.Turtle()
head.shape("circle")
head.color("yellow")
# 创建海绵宝宝的眼睛
eye1 = turtle.Turtle()
eye1.shape("circle")
eye1.color("blue")
eye1.penup()
eye1.goto(-30, 100)
eye1.pendown()
eye1.circle(20)
eye2 = turtle.Turtle()
eye2.shape("circle")
eye2.color("blue")
eye2.penup()
eye2.goto(30, 100)
eye2.pendown()
eye2.circle(20)
# 创建海绵宝宝的嘴巴
mouth = turtle.Turtle()
mouth.shape("circle")
mouth.color("red")
mouth.penup()
mouth.goto(0, 50)
mouth.pendown()
mouth.circle(50, 180)
# 创建海绵宝宝的身体
body = turtle.Turtle()
body.shape("square")
body.color("yellow")
body.penup()
body.goto(0, -100)
body.pendown()
body.shapesize(2, 3)
# 创建海绵宝宝的手
hand1 = turtle.Turtle()
hand1.shape("circle")
hand1.color("yellow")
hand1.penup()
hand1.goto(-70, -100)
hand1.pendown()
hand1.circle(30)
hand2 = turtle.Turtle()
hand2.shape("circle")
hand2.color("yellow")
hand2.penup()
hand2.goto(70, -100)
hand2.pendown()
hand2.circle(30)
# 创建海绵宝宝的腿
leg1 = turtle.Turtle()
leg1.shape("circle")
leg1.color("yellow")
leg1.penup()
leg1.goto(-30, -250)
leg1.pendown()
leg1.circle(30)
leg2 = turtle.Turtle()
leg2.shape("circle")
leg2.color("yellow")
leg2.penup()
leg2.goto(30, -250)
leg2.pendown()
leg2.circle(30)
turtle.done()
```
这段代码使用turtle库创建了一个海绵宝宝的图形,包括头部、眼睛、嘴巴、身体、手和腿。你可以运行这段代码来查看结果。希望能帮到你!如果有任何问题,请随时提问。
阅读全文