利用turtle库绘制皮卡丘
时间: 2023-07-06 08:41:48 浏览: 113
pikachu.py_pythonturtle库画皮卡丘_
5星 · 资源好评率100%
好的,以下是一个利用turtle库绘制皮卡丘的示例代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(500, 500)
turtle.bgcolor('#FED55D')
# 画皮卡丘的左耳朵
turtle.penup()
turtle.goto(-120, 100)
turtle.pendown()
turtle.setheading(150)
turtle.begin_fill()
turtle.circle(70, -100)
turtle.circle(30, -60)
turtle.circle(70, -40)
turtle.end_fill()
# 画皮卡丘的右耳朵
turtle.penup()
turtle.goto(120, 100)
turtle.pendown()
turtle.setheading(-30)
turtle.begin_fill()
turtle.circle(70, 100)
turtle.circle(30, 60)
turtle.circle(70, 40)
turtle.end_fill()
# 画皮卡丘的脸
turtle.penup()
turtle.goto(0, -50)
turtle.pendown()
turtle.setheading(0)
turtle.begin_fill()
turtle.circle(120)
turtle.end_fill()
# 画皮卡丘的眼睛
turtle.penup()
turtle.goto(-50, 60)
turtle.pendown()
turtle.setheading(0)
turtle.begin_fill()
turtle.circle(25)
turtle.end_fill()
turtle.penup()
turtle.goto(-50, 70)
turtle.pendown()
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(50, 60)
turtle.pendown()
turtle.begin_fill()
turtle.circle(25)
turtle.end_fill()
turtle.penup()
turtle.goto(50, 70)
turtle.pendown()
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 画皮卡丘的嘴巴
turtle.penup()
turtle.goto(-70, 0)
turtle.pendown()
turtle.setheading(-60)
turtle.circle(80, 120)
# 画皮卡丘的腮红
turtle.penup()
turtle.goto(-90, -30)
turtle.pendown()
turtle.setheading(0)
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(90, -30)
turtle.pendown()
turtle.setheading(0)
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
# 画皮卡丘的手
turtle.penup()
turtle.goto(-120, -50)
turtle.pendown()
turtle.setheading(-30)
turtle.begin_fill()
turtle.circle(30, 120)
turtle.circle(10, 180)
turtle.circle(30, 120)
turtle.end_fill()
turtle.penup()
turtle.goto(120, -50)
turtle.pendown()
turtle.setheading(-150)
turtle.begin_fill()
turtle.circle(30, 120)
turtle.circle(10, 180)
turtle.circle(30, 120)
turtle.end_fill()
# 画皮卡丘的脚
turtle.penup()
turtle.goto(-50, -120)
turtle.pendown()
turtle.setheading(-90)
turtle.begin_fill()
turtle.circle(50, 180)
turtle.forward(50)
turtle.end_fill()
turtle.penup()
turtle.goto(50, -120)
turtle.pendown()
turtle.setheading(-90)
turtle.begin_fill()
turtle.circle(50, 180)
turtle.forward(50)
turtle.end_fill()
# 完成绘制
turtle.done()
```
您可以运行这段代码,查看绘制的皮卡丘效果。
阅读全文