使用python绘画一个海绵宝宝
时间: 2024-06-09 07:08:16 浏览: 13
好的,以下是使用 Python 绘制海绵宝宝的示例代码:
```python
import turtle
# 设置画布
turtle.setup(800, 800)
turtle.bgcolor("#FDD7D7")
turtle.title("海绵宝宝")
# 画身体
turtle.penup()
turtle.goto(0, -200)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor("#F7A93C")
turtle.circle(200)
turtle.end_fill()
# 画眼睛
turtle.penup()
turtle.goto(-80, 80)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor("#FFFFFF")
turtle.circle(50)
turtle.end_fill()
turtle.penup()
turtle.goto(-80, 100)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor("#000000")
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(80, 80)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor("#FFFFFF")
turtle.circle(50)
turtle.end_fill()
turtle.penup()
turtle.goto(80, 100)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor("#000000")
turtle.circle(20)
turtle.end_fill()
# 画鼻子
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor("#F7A93C")
turtle.circle(30)
turtle.end_fill()
turtle.penup()
turtle.goto(0, -20)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor("#FFFFFF")
turtle.circle(10)
turtle.end_fill()
# 画嘴巴
turtle.penup()
turtle.goto(-100, -100)
turtle.pendown()
turtle.color("#000000")
turtle.width(10)
turtle.right(90)
turtle.circle(100, 180)
# 画裤子
turtle.penup()
turtle.goto(0, -200)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor("#4BACC6")
turtle.circle(200, 180)
turtle.goto(100, -200)
turtle.goto(100, -300)
turtle.goto(-100, -300)
turtle.goto(-100, -200)
turtle.end_fill()
# 画鞋子
turtle.penup()
turtle.goto(-100, -300)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor("#FFFFFF")
turtle.circle(50)
turtle.end_fill()
turtle.penup()
turtle.goto(100, -300)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor("#FFFFFF")
turtle.circle(50)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 显示画布
turtle.done()
```
运行代码后,会弹出一个窗口,显示绘制完成的海绵宝宝图案。如下图所示:
![海绵宝宝](https://img-blog.csdnimg.cn/20210510173630309.png)
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)