「Python绘图」绘制小猪佩奇

python 绘制小猪佩奇

一、预期结果

二、核心代码

import turtle
print("开始绘制小猪佩奇")
pen = turtle.Turtle()
pen.pensize(4)
#pen.hideturtle()

pen.speed(1000)

pen.color("#ff9bc0","pink")
pen.setheading(-30)
pen.pu()
pen.goto(-100,100)
pen.begin_fill()
pen.pd()
a=0.4
print("绘制鼻子")
for  i  in  range(120):
    if  0<=i<30  or  60<=i<90:
        a=a+0.08
        pen.lt(3)
        pen.fd(a)
    else:
        a=a-0.08
        pen.lt(3)
        pen.fd(a)
pen.end_fill()
pen.pu()
pen.seth(90)
pen.fd(25)
pen.setheading(0)
pen.fd(10)
pen.begin_fill()
pen.pd()
pen.circle(5)
pen.color("#A0522D")
pen.end_fill()
pen.pu()
pen.seth(0)
pen.fd(20)
pen.pd()
pen.pencolor("#ff9bc0")
pen.begin_fill()
pen.circle(5)
pen.color("#A0522D")
pen.end_fill()

print("绘制头部")
pen.color("#ff9bc0","pink")
pen.pu()
pen.seth(90)
pen.fd(41)
pen.seth(0)
pen.pd()
pen.begin_fill()
pen.seth(0)
pen.circle(-300,30)
pen.circle(-100,60)
pen.circle(-80,100)
pen.circle(-150,20)
pen.circle(-60,95)
pen.seth(161)
pen.circle(-300,15)
pen.pu()
pen.goto(-100,100)
pen.pd()
pen.seth(-30)
a=0.4



for  i  in  range(60):
    if  0<=i<30:
        a=a+0.08
        pen.lt(3)
        pen.fd(a)
    else:
        a=a-0.08
        pen.lt(3)
        pen.fd(a)
pen.end_fill()

print("绘制耳朵")
pen.color("#ff9bc0","pink")
pen.pu()
pen.seth(90)
pen.fd(-7)
pen.seth(0)
pen.fd(70)
pen.pd()
pen.begin_fill()
pen.seth(100)
pen.circle(-50,50)
pen.circle(-10,120)
pen.circle(-50,54)
pen.end_fill()
pen.pu()
pen.seth(90)
pen.fd(-12)
pen.seth(0)
pen.fd(30)
pen.pd()
pen.begin_fill()
pen.seth(100)
pen.circle(-50,50)
pen.circle(-10,120)
pen.circle(-50,56)
pen.end_fill()

pen.color("#ff9bc0","white")
pen.pu()
print("绘制眼睛")
pen.seth(90)
pen.fd(-20)
pen.seth(0)
pen.fd(-95)
pen.pd()
pen.begin_fill()
pen.circle(15)
pen.end_fill()
pen.color("black")
pen.pu()
pen.seth(90)
pen.fd(12)
pen.seth(0)
pen.fd(-3)
pen.pd()
pen.begin_fill()
pen.circle(3)
pen.end_fill()
pen.color("#ff9bc0","white")
pen.pu()
pen.seth(90)
pen.fd(-25)
pen.seth(0)
pen.fd(40)
pen.pd()
pen.begin_fill()
pen.circle(15)
pen.end_fill()
pen.color("black")
pen.pu()
pen.seth(90)
pen.fd(12)
pen.seth(0)
pen.fd(-3)
pen.pd()
pen.begin_fill()
pen.circle(3)
pen.end_fill()


print("绘制脸")
pen.color("#ff9bc0")
pen.pu()
pen.seth(90)
pen.fd(-95)
pen.seth(0)
pen.fd(65)
pen.pd()
pen.begin_fill()
pen.circle(30)
pen.end_fill()

print("绘制嘴巴")
pen.color("#EF4513")
pen.pu()
pen.seth(90)
pen.fd(15)
pen.seth(0)
pen.fd(-100)
pen.pd()
pen.seth(-80)
pen.circle(30,40)
pen.circle(40,80)

print("绘制身体")
pen.color("red","#FF6347")
pen.pu()
pen.seth(90)
pen.fd(-20)
pen.seth(0)
pen.fd(-78)
pen.pd()
pen.begin_fill()
pen.seth(-130)
pen.circle(100,10)
pen.circle(300,30)
pen.seth(0)
pen.fd(230)
pen.seth(90)
pen.circle(300,30)
pen.circle(100,3)
pen.color("#FF9BC0","#FF6464")
pen.seth(-135)
pen.circle(-80,63)
pen.circle(-150,24)
pen.end_fill()



print("绘制胳膊")
pen.color("#FF9BC0")
pen.pu()
pen.seth(90)
pen.fd(-40)
pen.seth(0)
pen.fd(-27)
pen.pd()
pen.seth(-160)
pen.circle(300,15)
pen.pu()
pen.seth(90)
pen.fd(15)
pen.seth(0)
pen.fd(0)
pen.pd()
pen.seth(-10)
pen.circle(-20,90)
pen.pu()
pen.seth(90)
pen.fd(30)
pen.seth(0)
pen.fd(237)
pen.pd()
pen.seth(-20)
pen.circle(-300,15)
pen.pu()
pen.seth(90)
pen.fd(20)
pen.seth(0)
pen.fd(0)
pen.pd()
pen.seth(-170)
pen.circle(20,90)


print("绘制腿和脚")
pen.pensize(10)
pen.color("#F08080")
pen.pu()
pen.seth(90)
pen.fd(-75)
pen.seth(0)
pen.fd(-180)
pen.pd()
pen.seth(-90)
pen.fd(40)
pen.seth(-180)
pen.color("black")
pen.pensize(15)
pen.fd(20)
pen.pensize(10)
pen.color("#F08080")
pen.pu()
pen.seth(90)
pen.fd(40)
pen.seth(0)
pen.fd(90)
pen.pd()
pen.seth(-90)
pen.fd(40)
pen.seth(-180)
pen.color("black")
pen.pensize(15)
pen.fd(20)


print("绘制尾巴")
pen.pensize(4)
pen.color("#FF9BC0")
pen.pu()
pen.seth(90)
pen.fd(70)
pen.seth(0)
pen.fd(95)
pen.pd()
pen.seth(0)
pen.circle(70,20)
pen.circle(10,330)
pen.circle(70,30)
# pen.mainloop()
# 隐藏画笔
pen.hideturtle()

print("绘制完成")
turtle.done()
相关推荐
tangliang_cn6 分钟前
java入门 自定义springboot starter
java·开发语言·spring boot
莫叫石榴姐7 分钟前
数据科学与SQL:组距分组分析 | 区间分布问题
大数据·人工智能·sql·深度学习·算法·机器学习·数据挖掘
程序猿阿伟7 分钟前
《智能指针频繁创建销毁:程序性能的“隐形杀手”》
java·开发语言·前端
新知图书18 分钟前
Rust编程与项目实战-模块std::thread(之一)
开发语言·后端·rust
威威猫的栗子20 分钟前
Python Turtle召唤童年:喜羊羊与灰太狼之懒羊羊绘画
开发语言·python
力透键背20 分钟前
display: none和visibility: hidden的区别
开发语言·前端·javascript
bluefox197921 分钟前
使用 Oracle.DataAccess.Client 驱动 和 OleDB 调用Oracle 函数的区别
开发语言·c#
如若12329 分钟前
利用 `OpenCV` 和 `Matplotlib` 库进行图像读取、颜色空间转换、掩膜创建、颜色替换
人工智能·opencv·matplotlib
YRr YRr1 小时前
深度学习:神经网络中的损失函数的使用
人工智能·深度学习·神经网络
ö Constancy1 小时前
c++ 笔记
开发语言·c++