python画海绵宝宝代码_Python使用turtle画海绵宝宝源码
时间: 2023-08-21 22:38:31 浏览: 1223
Python海绵宝宝源码.py
5星 · 资源好评率100%
以下是使用Python的turtle库画海绵宝宝的代码:
```python
import turtle
# 设置海绵宝宝的颜色
spongebob_color = "#FEE12B"
spongebob_highlight_color = "#FDD835"
spongebob_shadow_color = "#C6A300"
# 创建海绵宝宝的画笔
spongebob_pen = turtle.Turtle()
spongebob_pen.pensize(3)
# 画海绵宝宝的头部
spongebob_pen.fillcolor(spongebob_color)
spongebob_pen.begin_fill()
spongebob_pen.circle(100)
spongebob_pen.end_fill()
# 画海绵宝宝的眼睛
spongebob_pen.penup()
spongebob_pen.goto(-40, 120)
spongebob_pen.pendown()
spongebob_pen.fillcolor("white")
spongebob_pen.begin_fill()
spongebob_pen.circle(20)
spongebob_pen.end_fill()
spongebob_pen.penup()
spongebob_pen.goto(-30, 130)
spongebob_pen.pendown()
spongebob_pen.fillcolor("black")
spongebob_pen.begin_fill()
spongebob_pen.circle(10)
spongebob_pen.end_fill()
spongebob_pen.penup()
spongebob_pen.goto(40, 120)
spongebob_pen.pendown()
spongebob_pen.fillcolor("white")
spongebob_pen.begin_fill()
spongebob_pen.circle(20)
spongebob_pen.end_fill()
spongebob_pen.penup()
spongebob_pen.goto(50, 130)
spongebob_pen.pendown()
spongebob_pen.fillcolor("black")
spongebob_pen.begin_fill()
spongebob_pen.circle(10)
spongebob_pen.end_fill()
# 画海绵宝宝的鼻子
spongebob_pen.penup()
spongebob_pen.goto(0, 80)
spongebob_pen.pendown()
spongebob_pen.fillcolor("red")
spongebob_pen.begin_fill()
spongebob_pen.circle(20)
spongebob_pen.end_fill()
# 画海绵宝宝的嘴巴
spongebob_pen.penup()
spongebob_pen.goto(-70, 20)
spongebob_pen.pendown()
spongebob_pen.pencolor("black")
spongebob_pen.fillcolor(spongebob_color)
spongebob_pen.begin_fill()
spongebob_pen.right(45)
spongebob_pen.forward(80)
spongebob_pen.right(90)
spongebob_pen.circle(50, -180)
spongebob_pen.right(90)
spongebob_pen.forward(80)
spongebob_pen.end_fill()
# 画海绵宝宝的牙齿
spongebob_pen.penup()
spongebob_pen.goto(-30, 0)
spongebob_pen.pendown()
spongebob_pen.pencolor("white")
spongebob_pen.fillcolor("white")
spongebob_pen.begin_fill()
spongebob_pen.right(45)
spongebob_pen.forward(20)
spongebob_pen.right(90)
spongebob_pen.forward(20)
spongebob_pen.right(90)
spongebob_pen.forward(20)
spongebob_pen.right(90)
spongebob_pen.forward(20)
spongebob_pen.right(90)
spongebob_pen.end_fill()
spongebob_pen.penup()
spongebob_pen.goto(10, 0)
spongebob_pen.pendown()
spongebob_pen.pencolor("white")
spongebob_pen.fillcolor("white")
spongebob_pen.begin_fill()
spongebob_pen.right(45)
spongebob_pen.forward(20)
spongebob_pen.right(90)
spongebob_pen.forward(20)
spongebob_pen.right(90)
spongebob_pen.forward(20)
spongebob_pen.right(90)
spongebob_pen.forward(20)
spongebob_pen.right(90)
spongebob_pen.end_fill()
# 画海绵宝宝的衣服
spongebob_pen.penup()
spongebob_pen.goto(-120, -100)
spongebob_pen.pendown()
spongebob_pen.fillcolor(spongebob_color)
spongebob_pen.begin_fill()
spongebob_pen.right(45)
spongebob_pen.forward(200)
spongebob_pen.right(45)
spongebob_pen.forward(50)
spongebob_pen.right(90)
spongebob_pen.forward(100)
spongebob_pen.right(90)
spongebob_pen.forward(50)
spongebob_pen.right(45)
spongebob_pen.forward(200)
spongebob_pen.right(135)
spongebob_pen.forward(50)
spongebob_pen.right(90)
spongebob_pen.forward(100)
spongebob_pen.right(90)
spongebob_pen.forward(50)
spongebob_pen.right(45)
spongebob_pen.end_fill()
# 画海绵宝宝的衣服的阴影
spongebob_pen.penup()
spongebob_pen.goto(-70, -180)
spongebob_pen.pendown()
spongebob_pen.fillcolor(spongebob_shadow_color)
spongebob_pen.begin_fill()
spongebob_pen.right(45)
spongebob_pen.forward(100)
spongebob_pen.right(45)
spongebob_pen.forward(50)
spongebob_pen.right(90)
spongebob_pen.forward(100)
spongebob_pen.right(90)
spongebob_pen.forward(50)
spongebob_pen.right(45)
spongebob_pen.forward(100)
spongebob_pen.right(135)
spongebob_pen.forward(50)
spongebob_pen.right(90)
spongebob_pen.forward(100)
spongebob_pen.right(90)
spongebob_pen.forward(50)
spongebob_pen.right(45)
spongebob_pen.end_fill()
# 画海绵宝宝的衣服的高光
spongebob_pen.penup()
spongebob_pen.goto(-100, -100)
spongebob_pen.pendown()
spongebob_pen.fillcolor(spongebob_highlight_color)
spongebob_pen.begin_fill()
spongebob_pen.right(45)
spongebob_pen.forward(160)
spongebob_pen.right(45)
spongebob_pen.forward(50)
spongebob_pen.right(90)
spongebob_pen.forward(80)
spongebob_pen.right(90)
spongebob_pen.forward(50)
spongebob_pen.right(45)
spongebob_pen.forward(160)
spongebob_pen.right(135)
spongebob_pen.forward(50)
spongebob_pen.right(90)
spongebob_pen.forward(80)
spongebob_pen.right(90)
spongebob_pen.forward(50)
spongebob_pen.right(45)
spongebob_pen.end_fill()
# 隐藏画笔
spongebob_pen.hideturtle()
# 显示画布
turtle.done()
```
运行代码后,会弹出一个窗口展示画出的海绵宝宝图案。
阅读全文