Python调用turtle库画皮卡丘
时间: 2023-06-11 13:04:53 浏览: 114
好的,我可以为您展示如何使用Python的Turtle库来画皮卡丘。
下面是绘制皮卡丘的Python代码:
```python
import turtle
# 创建一个新窗口
win = turtle.Screen()
win.bgcolor("white")
# 画布的大小
win.setup(width=600, height=600)
# 将画笔移到屏幕中央,准备画脸
face = turtle.Turtle()
face.color("black")
face.fillcolor("yellow")
face.penup()
face.goto(0, -100)
face.pendown()
face.begin_fill()
face.circle(200)
face.end_fill()
# 画左耳
left_ear = turtle.Turtle()
left_ear.color("black")
left_ear.fillcolor("black")
left_ear.penup()
left_ear.goto(-150, 180)
left_ear.pendown()
left_ear.begin_fill()
left_ear.right(135)
left_ear.circle(100, -90)
left_ear.left(90)
left_ear.circle(100, -45)
left_ear.end_fill()
# 画右耳
right_ear = turtle.Turtle()
right_ear.color("black")
right_ear.fillcolor("black")
right_ear.penup()
right_ear.goto(150, 180)
right_ear.pendown()
right_ear.begin_fill()
right_ear.left(135)
right_ear.circle(-100, -90)
right_ear.right(90)
right_ear.circle(-100, -45)
right_ear.end_fill()
# 画左眼
left_eye = turtle.Turtle()
left_eye.color("black")
left_eye.fillcolor("white")
left_eye.penup()
left_eye.goto(-80, 50)
left_eye.pendown()
left_eye.begin_fill()
left_eye.circle(40)
left_eye.end_fill()
# 画右眼
right_eye = turtle.Turtle()
right_eye.color("black")
right_eye.fillcolor("white")
right_eye.penup()
right_eye.goto(80, 50)
right_eye.pendown()
right_eye.begin_fill()
right_eye.circle(40)
right_eye.end_fill()
# 左眼珠
left_pupil = turtle.Turtle()
left_pupil.color("black")
left_pupil.fillcolor("black")
left_pupil.penup()
left_pupil.goto(-80, 20)
left_pupil.pendown()
left_pupil.begin_fill()
left_pupil.circle(20)
left_pupil.end_fill()
# 画右眼珠
right_pupil = turtle.Turtle()
right_pupil.color("black")
right_pupil.fillcolor("black")
right_pupil.penup()
right_pupil.goto(80, 20)
right_pupil.pendown()
right_pupil.begin_fill()
right_pupil.circle(20)
right_pupil.end_fill()
# 画鼻子
nose = turtle.Turtle()
nose.color("black")
nose.fillcolor("black")
nose.penup()
nose.goto(0, 60)
nose.pendown()
nose.begin_fill()
nose.circle(30)
nose.end_fill()
# 画嘴巴
mouth = turtle.Turtle()
mouth.color("black")
mouth.penup()
mouth.goto(-100, -40)
mouth.pendown()
mouth.right(90)
mouth.circle(100, 180)
# 使窗口保持打开状态
turtle.done()
```
运行上述代码后,您可以在Turtle窗口中看到绘制的皮卡丘。
阅读全文