帮我用Python的turtle画一个海绵宝宝
时间: 2024-03-28 11:28:39 浏览: 578
好的,以下是画海绵宝宝的Python代码:
```python
import turtle
# 设置海绵宝宝的颜色和大小
spongebob_color = "#FEE12B"
spongebob_size = 100
# 创建一个海绵宝宝的海葵
def seaweed():
turtle.pensize(10)
turtle.penup()
turtle.goto(-200, -150)
turtle.pendown()
turtle.color("#00BA84")
for i in range(4):
turtle.forward(50)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.penup()
turtle.goto(-180, -50)
turtle.pendown()
for i in range(6):
turtle.forward(30)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(30)
turtle.left(90)
turtle.forward(50)
turtle.left(90)
# 创建一个海绵宝宝的身体
def spongebob_body():
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.begin_fill()
turtle.color(spongebob_color)
turtle.circle(spongebob_size)
turtle.end_fill()
# 创建一个海绵宝宝的眼睛
def spongebob_eyes():
turtle.penup()
turtle.goto(-40, 60)
turtle.pendown()
turtle.begin_fill()
turtle.color("white")
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(-40, 80)
turtle.pendown()
turtle.begin_fill()
turtle.color("black")
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(40, 60)
turtle.pendown()
turtle.begin_fill()
turtle.color("white")
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(40, 80)
turtle.pendown()
turtle.begin_fill()
turtle.color("black")
turtle.circle(10)
turtle.end_fill()
# 创建一个海绵宝宝的鼻子
def spongebob_nose():
turtle.penup()
turtle.goto(0, 30)
turtle.pendown()
turtle.begin_fill()
turtle.color("#FEAE00")
turtle.circle(15)
turtle.end_fill()
# 创建一个海绵宝宝的嘴巴
def spongebob_mouth():
turtle.penup()
turtle.goto(-50, -20)
turtle.pendown()
turtle.pensize(6)
turtle.color("black")
turtle.right(45)
turtle.forward(40)
turtle.right(90)
turtle.forward(40)
turtle.right(45)
# 创建一个海绵宝宝的牙齿
def spongebob_teeth():
turtle.penup()
turtle.goto(-20, -20)
turtle.pendown()
turtle.begin_fill()
turtle.color("white")
turtle.forward(20)
turtle.right(90)
turtle.forward(10)
turtle.right(90)
turtle.forward(20)
turtle.right(90)
turtle.forward(10)
turtle.right(90)
turtle.end_fill()
turtle.penup()
turtle.goto(20, -20)
turtle.pendown()
turtle.begin_fill()
turtle.color("white")
turtle.forward(20)
turtle.left(90)
turtle.forward(10)
turtle.left(90)
turtle.forward(20)
turtle.left(90)
turtle.forward(10)
turtle.left(90)
turtle.end_fill()
# 创建一个海绵宝宝的胡须
def spongebob_whiskers():
turtle.penup()
turtle.goto(-60, 0)
turtle.pendown()
turtle.color("black")
turtle.right(20)
turtle.forward(50)
turtle.right(160)
turtle.forward(50)
turtle.penup()
turtle.goto(-60, -10)
turtle.pendown()
turtle.right(10)
turtle.forward(50)
turtle.right(160)
turtle.forward(50)
turtle.penup()
turtle.goto(-60, -20)
turtle.pendown()
turtle.right(5)
turtle.forward(50)
turtle.right(160)
turtle.forward(50)
turtle.penup()
turtle.goto(60, 0)
turtle.pendown()
turtle.right(135)
turtle.forward(50)
turtle.right(20)
turtle.forward(50)
turtle.penup()
turtle.goto(60, -10)
turtle.pendown()
turtle.right(170)
turtle.forward(50)
turtle.right(20)
turtle.forward(50)
turtle.penup()
turtle.goto(60, -20)
turtle.pendown()
turtle.right(175)
turtle.forward(50)
turtle.right(20)
turtle.forward(50)
# 创建一个海绵宝宝的裤子
def spongebob_pants():
turtle.penup()
turtle.goto(0, -spongebob_size)
turtle.pendown()
turtle.begin_fill()
turtle.color("#00AEEF")
turtle.circle(spongebob_size, 180)
turtle.end_fill()
turtle.penup()
turtle.goto(0, -spongebob_size)
turtle.pendown()
turtle.color("white")
turtle.right(90)
turtle.forward(spongebob_size/2)
turtle.left(90)
turtle.forward(spongebob_size/2)
turtle.right(90)
turtle.forward(spongebob_size/2)
turtle.left(90)
turtle.forward(spongebob_size/2)
turtle.right(90)
turtle.forward(spongebob_size/2)
turtle.penup()
turtle.goto(0, -spongebob_size/2)
turtle.pendown()
turtle.begin_fill()
turtle.color("#00AEEF")
turtle.circle(spongebob_size/2, 180)
turtle.end_fill()
# 绘制海绵宝宝
seaweed()
spongebob_body()
spongebob_eyes()
spongebob_nose()
spongebob_mouth()
spongebob_teeth()
spongebob_whiskers()
spongebob_pants()
# 隐藏画笔
turtle.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
运行以上代码,就可以在窗口中看到一个可爱的海绵宝宝了。
阅读全文