Python画会动的皮卡丘
时间: 2023-11-05 07:05:24 浏览: 133
这是一个IT类问题,可以回答。
要画会动的皮卡丘,需要用到Python中的turtle库和time库。
以下是画皮卡丘的代码:
```python
import turtle
import time
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor('#FFC0CB')
# 设置画笔大小和速度
turtle.pensize(5)
turtle.speed(2)
# 画皮卡丘的耳朵
turtle.color('black', '#FCD116')
turtle.begin_fill()
turtle.left(90)
turtle.forward(60)
turtle.right(120)
turtle.forward(60)
turtle.right(120)
turtle.forward(60)
turtle.right(150)
turtle.end_fill()
turtle.penup()
turtle.goto(100, 60)
turtle.pendown()
turtle.begin_fill()
turtle.left(90)
turtle.forward(60)
turtle.right(120)
turtle.forward(60)
turtle.right(120)
turtle.forward(60)
turtle.right(150)
turtle.end_fill()
# 画皮卡丘的脸
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.color('black', '#FDD835')
turtle.begin_fill()
turtle.circle(120)
turtle.end_fill()
# 画皮卡丘的眼睛
turtle.penup()
turtle.goto(-30, 150)
turtle.pendown()
turtle.color('black', 'white')
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
turtle.penup()
turtle.goto(-30, 170)
turtle.pendown()
turtle.color('black', 'black')
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(30, 150)
turtle.pendown()
turtle.color('black', 'white')
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
turtle.penup()
turtle.goto(30, 170)
turtle.pendown()
turtle.color('black', 'black')
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 画皮卡丘的嘴巴
turtle.penup()
turtle.goto(-70, 20)
turtle.pendown()
turtle.color('black', 'black')
turtle.begin_fill()
turtle.right(45)
turtle.circle(100, 90)
turtle.right(180)
turtle.circle(-100, 90)
turtle.end_fill()
turtle.penup()
turtle.goto(-70, 20)
turtle.pendown()
turtle.color('#FFC0CB', '#FFC0CB')
turtle.begin_fill()
turtle.right(135)
turtle.circle(80, 90)
turtle.right(180)
turtle.circle(-80, 90)
turtle.end_fill()
# 画皮卡丘的胳膊
turtle.penup()
turtle.goto(-150, -80)
turtle.pendown()
turtle.color('black', '#FDD835')
turtle.begin_fill()
turtle.right(45)
turtle.forward(100)
turtle.right(180)
turtle.circle(-30, 120)
turtle.right(180)
turtle.forward(100)
turtle.end_fill()
turtle.penup()
turtle.goto(150, -80)
turtle.pendown()
turtle.color('black', '#FDD835')
turtle.begin_fill()
turtle.right(45)
turtle.forward(100)
turtle.right(180)
turtle.circle(30, -120)
turtle.right(180)
turtle.forward(100)
turtle.end_fill()
# 画皮卡丘的脚
turtle.penup()
turtle.goto(-60, -250)
turtle.pendown()
turtle.color('black', '#FDD835')
turtle.begin_fill()
turtle.left(45)
turtle.forward(100)
turtle.right(180)
turtle.circle(-30, 120)
turtle.right(180)
turtle.forward(100)
turtle.end_fill()
turtle.penup()
turtle.goto(60, -250)
turtle.pendown()
turtle.color('black', '#FDD835')
turtle.begin_fill()
turtle.left(45)
turtle.forward(100)
turtle.right(180)
turtle.circle(30, -120)
turtle.right(180)
turtle.forward(100)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 使皮卡丘动起来
while True:
turtle.penup()
turtle.goto(-150, -80)
turtle.pendown()
turtle.color('black', '#FDD835')
turtle.begin_fill()
turtle.right(45)
turtle.forward(100)
turtle.right(180)
turtle.circle(-30, 120)
turtle.right(180)
turtle.forward(100)
turtle.end_fill()
turtle.penup()
turtle.goto(150, -80)
turtle.pendown()
turtle.color('black', '#FDD835')
turtle.begin_fill()
turtle.right(45)
turtle.forward(100)
turtle.right(180)
turtle.circle(30, -120)
turtle.right(180)
turtle.forward(100)
turtle.end_fill()
time.sleep(0.5)
turtle.clear()
```
运行以上代码,即可在Python中画出会动的皮卡丘。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)