用Python画一个海绵宝宝
时间: 2023-11-16 21:19:20 浏览: 417
好的,这里是一个用Python绘制海绵宝宝的示例代码,使用的是Python的turtle模块。
```python
import turtle
# 设置画笔的颜色和大小
turtle.pensize(4)
turtle.color("yellow", "yellow")
# 绘制海绵宝宝的脸部
turtle.begin_fill()
turtle.circle(100)
turtle.end_fill()
# 绘制海绵宝宝的眼睛
turtle.penup()
turtle.goto(-50, 120)
turtle.pendown()
turtle.color("white", "white")
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(50, 120)
turtle.pendown()
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
# 绘制海绵宝宝的眼球
turtle.penup()
turtle.goto(-40, 130)
turtle.pendown()
turtle.color("black", "black")
turtle.begin_fill()
turtle.circle(8)
turtle.end_fill()
turtle.penup()
turtle.goto(60, 130)
turtle.pendown()
turtle.begin_fill()
turtle.circle(8)
turtle.end_fill()
# 绘制海绵宝宝的鼻子
turtle.penup()
turtle.goto(0, 80)
turtle.pendown()
turtle.color("black", "red")
turtle.begin_fill()
turtle.circle(15)
turtle.end_fill()
# 绘制海绵宝宝的嘴巴
turtle.penup()
turtle.goto(-70, 20)
turtle.pendown()
turtle.color("black", "white")
turtle.begin_fill()
turtle.right(90)
turtle.circle(70, 180)
turtle.end_fill()
# 绘制海绵宝宝的牙齿
turtle.penup()
turtle.goto(-50, 5)
turtle.pendown()
turtle.color("white", "white")
turtle.begin_fill()
turtle.forward(15)
turtle.left(90)
turtle.forward(20)
turtle.left(90)
turtle.forward(15)
turtle.end_fill()
turtle.penup()
turtle.goto(35, 5)
turtle.pendown()
turtle.begin_fill()
turtle.forward(15)
turtle.left(90)
turtle.forward(20)
turtle.left(90)
turtle.forward(15)
turtle.end_fill()
# 绘制海绵宝宝的舌头
turtle.penup()
turtle.goto(-30, -20)
turtle.pendown()
turtle.color("red", "red")
turtle.begin_fill()
turtle.circle(20, 180)
turtle.end_fill()
# 绘制海绵宝宝的腮红
turtle.penup()
turtle.goto(-80, 60)
turtle.pendown()
turtle.color("pink", "pink")
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(80, 60)
turtle.pendown()
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 点击窗口关闭画布
turtle.exitonclick()
```
希望这个示例能够帮助您了解如何使用Python绘制图形。如果您有任何问题,请随时问我。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)