请用Python画一只皮卡丘
时间: 2024-12-03 21:16:58 浏览: 13
用python画一只可爱的皮卡丘实例
5星 · 资源好评率100%
要用Python画一只皮卡丘,我们可以使用`turtle`库来实现。以下是一个简单的示例代码:
```python
import turtle
# 设置屏幕
screen = turtle.Screen()
screen.setup(width=800, height=600)
screen.bgcolor("yellow")
screen.title("皮卡丘")
# 创建画笔
pikachu = turtle.Turtle()
pikachu.speed(10)
pikachu.pensize(3)
# 画皮卡丘的脸
pikachu.penup()
pikachu.goto(0, -100)
pikachu.pendown()
pikachu.color("black", "yellow")
pikachu.begin_fill()
pikachu.circle(100)
pikachu.end_fill()
# 画左耳朵
pikachu.penup()
pikachu.goto(-70, 50)
pikachu.pendown()
pikachu.color("black", "yellow")
pikachu.begin_fill()
pikachu.left(45)
pikachu.forward(70)
pikachu.left(90)
pikachu.forward(70)
pikachu.left(135)
pikachu.circle(-50, 90)
pikachu.end_fill()
# 画右耳朵
pikachu.penup()
pikachu.goto(70, 50)
pikachu.pendown()
pikachu.color("black", "yellow")
pikachu.begin_fill()
pikachu.right(45)
pikachu.forward(70)
pikachu.right(90)
pikachu.forward(70)
pikachu.right(135)
pikachu.circle(50, 90)
pikachu.end_fill()
# 画左眼
pikachu.penup()
pikachu.goto(-40, 20)
pikachu.pendown()
pikachu.color("black", "white")
pikachu.begin_fill()
pikachu.circle(10)
pikachu.end_fill()
# 画右眼
pikachu.penup()
pikachu.goto(40, 20)
pikachu.pendown()
pikachu.color("black", "white")
pikachu.begin_fill()
pikachu.circle(10)
pikachu.end_fill()
# 画鼻子
pikachu.penup()
pikachu.goto(0, 30)
pikachu.pendown()
pikachu.color("black", "black")
pikachu.begin_fill()
pikachu.circle(5)
pikachu.end_fill()
# 画嘴巴
pikachu.penup()
pikachu.goto(0, 30)
pikachu.pendown()
pikachu.right(90)
pikachu.circle(20, 180)
# 隐藏画笔
pikachu.hideturtle()
# 保持窗口打开
turtle.done()
```
这个代码使用了`turtle`库来绘制一个简单的皮卡丘图案。你可以在Python环境中运行这段代码,看到一个简易的皮卡丘图案。
阅读全文