用python调用turtle库绘制一幅皮卡丘图画
时间: 2023-08-04 13:38:51 浏览: 80
使用Python的turtle模块绘制皮卡丘图案
好的,以下是绘制皮卡丘图画的Python代码:
```
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 设置画笔大小和颜色
turtle.pensize(3)
turtle.pencolor("black")
# 绘制皮卡丘头部
turtle.fillcolor("#FDB813")
turtle.begin_fill()
turtle.circle(150)
turtle.end_fill()
# 绘制皮卡丘耳朵
turtle.fillcolor("#FDB813")
turtle.begin_fill()
turtle.setheading(60)
turtle.circle(-100, 60)
turtle.setheading(180)
turtle.circle(-20, 180)
turtle.setheading(-60)
turtle.circle(-100, 60)
turtle.setheading(0)
turtle.end_fill()
turtle.fillcolor("#FDB813")
turtle.begin_fill()
turtle.setheading(60)
turtle.circle(100, 60)
turtle.setheading(180)
turtle.circle(20, 180)
turtle.setheading(-60)
turtle.circle(100, 60)
turtle.setheading(0)
turtle.end_fill()
# 绘制皮卡丘眼睛
turtle.penup()
turtle.goto(-60, 120)
turtle.pendown()
turtle.fillcolor("white")
turtle.begin_fill()
turtle.circle(35)
turtle.end_fill()
turtle.penup()
turtle.goto(-60, 125)
turtle.pendown()
turtle.fillcolor("black")
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(60, 120)
turtle.pendown()
turtle.fillcolor("white")
turtle.begin_fill()
turtle.circle(35)
turtle.end_fill()
turtle.penup()
turtle.goto(60, 125)
turtle.pendown()
turtle.fillcolor("black")
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
# 绘制皮卡丘脸颊
turtle.penup()
turtle.goto(0, 80)
turtle.pendown()
turtle.fillcolor("#FDB813")
turtle.begin_fill()
turtle.setheading(180)
turtle.circle(80, 180)
turtle.setheading(0)
turtle.circle(-80, 180)
turtle.end_fill()
# 绘制皮卡丘嘴巴
turtle.penup()
turtle.goto(-80, 0)
turtle.pendown()
turtle.setheading(-60)
turtle.circle(80, 120)
turtle.setheading(0)
turtle.circle(80, 120)
# 绘制皮卡丘鼻子
turtle.penup()
turtle.goto(0, 40)
turtle.pendown()
turtle.fillcolor("black")
turtle.begin_fill()
turtle.circle(15)
turtle.end_fill()
# 绘制皮卡丘红色脸颊
turtle.penup()
turtle.goto(0, 80)
turtle.pendown()
turtle.fillcolor("red")
turtle.begin_fill()
turtle.setheading(180)
turtle.circle(30, 180)
turtle.setheading(0)
turtle.circle(-30, 180)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 完成绘制
turtle.done()
```
运行这段代码,即可在画布上绘制出一幅皮卡丘图画。
阅读全文