python画海绵宝宝的代码
时间: 2023-09-24 19:04:22 浏览: 126
下面是一段使用Python绘制海绵宝宝的代码:
```python
import turtle
# 创建绘图窗口
window = turtle.Screen()
window.bgcolor("white")
# 创建海绵宝宝的身体
body = turtle.Turtle()
body.shape("square")
body.color("yellow")
body.penup()
# 创建海绵宝宝的眼睛
eye = turtle.Turtle()
eye.shape("circle")
eye.color("blue")
eye.penup()
eye.goto(-30, 0)
# 创建海绵宝宝的眼珠
pupil = turtle.Turtle()
pupil.shape("circle")
pupil.color("black")
pupil.penup()
pupil.goto(-30, 0)
pupil.setheading(270)
pupil.forward(10)
# 创建海绵宝宝的嘴巴
mouth = turtle.Turtle()
mouth.shape("triangle")
mouth.color("red")
mouth.penup()
mouth.goto(-10, -30)
# 创建海绵宝宝的牙齿
tooth = turtle.Turtle()
tooth.shape("square")
tooth.color("white")
tooth.penup()
tooth.goto(-20, -30)
tooth.setheading(270)
tooth.forward(20)
# 隐藏乌龟笔画
turtle.hideturtle()
# 关闭绘图窗口
turtle.done()
```
运行这段代码,将会在一个绘图窗口中显示出海绵宝宝的形象。你可以根据需要调整绘制的位置、颜色和大小等参数。希望能对你有所帮助!