鱼C论坛

 找回密码
 立即注册
查看: 168|回复: 4

[作品展示] python小猪佩奇

[复制链接]
发表于 2025-7-23 19:14:19 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
用python的turtle库画的小猪佩奇
  1. from turtle import *

  2. def nose(): #鼻子   
  3.     penup()
  4.     goto(-100,100)
  5.     setheading(-30)
  6.     color((255,155,192),"pink") #画笔色是浅粉,填充色是粉色
  7.     pendown()
  8.     begin_fill()
  9.     #绘制一个椭圆作为鼻子的轮廓
  10.     segment=0.4
  11.     for i in range(120):
  12.         if 0<=i<30 or 60<=i<90:
  13.             segment=segment+0.08
  14.             left(3)
  15.             forward(segment)
  16.         else:
  17.             segment=segment-0.08
  18.             left(3)
  19.             forward(segment)
  20.     end_fill()
  21.     #左鼻孔
  22.     penup()
  23.     setheading(90)
  24.     forward(25)
  25.     setheading(0)
  26.     forward(10)
  27.     color((255,155,192),(160,82,45)) #画笔色是浅粉,填充色是黄土赭色
  28.     pendown()
  29.     begin_fill()
  30.     circle(5)
  31.     end_fill()
  32.     #右鼻孔
  33.     penup()
  34.     setheading(0)
  35.     forward(20)
  36.     pendown()
  37.     begin_fill()
  38.     circle(5)
  39.     end_fill()

  40. def head():#头
  41.     penup()
  42.     goto(-69,167)
  43.     pendown()
  44.     color((255,155,192),"pink")
  45.     begin_fill()
  46.     setheading(180)
  47.     circle(300,-30)
  48.     circle(100,-60)
  49.     circle(80,-100)
  50.     circle(150,-20)
  51.     circle(60,-95)
  52.     setheading(161)
  53.     circle(-300,15)
  54.    
  55.     #勾画出右半个鼻子的轮廓,避免填充时覆盖掉
  56.     penup()
  57.     goto(-100,100)
  58.     pendown()
  59.     setheading(-30)
  60.     segment=0.4
  61.     for i in range(60):
  62.         if 0<=i<30 or 60<=i<90:
  63.             segment=segment+0.08
  64.             left(3)
  65.             forward(segment)
  66.         else:
  67.             segment=segment-0.08
  68.             left(3)
  69.             forward(segment)
  70.     end_fill()

  71. def ears(): #耳朵
  72.     color((255,155,192),"pink")
  73.     #左耳朵
  74.     penup()
  75.     goto(0,160)
  76.     pendown()
  77.     begin_fill()
  78.     setheading(100)
  79.     circle(-50,50)
  80.     circle(-10,120)
  81.     circle(-50,54)
  82.     end_fill()
  83.     #右耳朵
  84.     penup()
  85.     setheading(90)
  86.     forward(-12)
  87.     setheading(0)
  88.     forward(30)
  89.     pendown()
  90.     begin_fill()
  91.     setheading(100)
  92.     circle(-50,50)
  93.     circle(-10,120)
  94.     circle(-50,56)
  95.     end_fill()

  96. def eyes():#眼睛
  97.     #左眼框
  98.     color((255,155,192),"white")
  99.     penup()
  100.     setheading(90)
  101.     forward(-20)
  102.     setheading(0)
  103.     forward(-95)
  104.     pendown()
  105.     begin_fill()
  106.     circle(15)
  107.     end_fill()
  108.     #左眼珠
  109.     color("black")
  110.     penup()
  111.     setheading(90)
  112.     forward(12)
  113.     setheading(0)
  114.     forward(-3)
  115.     pendown()
  116.     begin_fill()
  117.     circle(3)
  118.     end_fill()
  119.     #右眼框
  120.     color((255,155,192),"white")
  121.     penup()
  122.     setheading(90)
  123.     forward(-25)
  124.     setheading(0)
  125.     forward(40)
  126.     pendown()
  127.     begin_fill()
  128.     circle(15)
  129.     end_fill()
  130.     #右眼珠
  131.     color("black")
  132.     penup()
  133.     setheading(90)
  134.     forward(12)
  135.     setheading(0)
  136.     forward(-3)
  137.     pendown()
  138.     begin_fill()
  139.     circle(3)
  140.     end_fill()

  141. def cheek():#腮
  142.     penup()
  143.     goto(80,10)
  144.     setheading(0)
  145.     color((255,155,192))
  146.     pendown()
  147.     begin_fill()
  148.     circle(30)
  149.     end_fill()


  150. def mouth(): #嘴
  151.     penup()
  152.     goto(-20,30)
  153.     color(239,69,19)
  154.     pendown()
  155.     setheading(-80)
  156.     circle(35,120)

  157. def body():#身体   
  158.     color("red",(255,99,71))
  159.     #身体左边的曲线
  160.     penup()
  161.     goto(-32,-8)
  162.     pendown()
  163.     begin_fill()
  164.     setheading(-130)   
  165.     circle(100,10)
  166.     circle(300,30)
  167.     #身体底边
  168.     setheading(0)
  169.     forward(230)
  170.     #身体右边的曲线
  171.     setheading(90)   
  172.     circle(300,30)
  173.     circle(100,3)
  174.     color((255,155,192),(255,100,100))
  175.     #把脸上的下巴颏画出来,避免填充时覆盖掉
  176.     setheading(-135)
  177.     circle(-80,63)
  178.     circle(-150,24)
  179.     end_fill()


  180. def hands():#手
  181.     color((255,155,192))
  182.     # 左手的中间手指
  183.     penup()
  184.     goto(-56,-45)
  185.     pendown()
  186.     setheading(-160)
  187.     circle(300,15)
  188.     #通过一个弧形表示另外两根手指
  189.     penup()
  190.     setheading(90)
  191.     forward(15)
  192.     setheading(0)
  193.     pendown()
  194.     setheading(-10)
  195.     circle(-20,90)
  196.     #右手的中间手指
  197.     penup()
  198.     setheading(90)
  199.     forward(30)
  200.     setheading(0)
  201.     forward(237)
  202.     pendown()
  203.     setheading(-20)
  204.     circle(-300,15)
  205.     #通过一个弧形表示另外两根手指
  206.     penup()
  207.     setheading(90)
  208.     forward(20)
  209.     setheading(0)
  210.     pendown()
  211.     setheading(-170)
  212.     circle(20,90)

  213. def feet():#腿和脚
  214.     #左腿
  215.     pensize(10)
  216.     color((240,128,128))
  217.     penup()
  218.     goto(2,-177)
  219.     pendown()
  220.     setheading(-90)
  221.     forward(40)
  222.     setheading(-180)
  223.     #左脚
  224.     color("black")
  225.     pensize(15)
  226.     forward(20)
  227.     #右腿
  228.     pensize(10)
  229.     color((240,128,128))
  230.     penup()
  231.     setheading(90)
  232.     forward(40)
  233.     setheading(0)
  234.     forward(90)
  235.     pendown()
  236.     setheading(-90)
  237.     forward(40)
  238.     setheading(-180)
  239.     #右脚
  240.     color("black")
  241.     pensize(15)
  242.     forward(20)

  243. def tail():#尾巴
  244.     pensize(4)
  245.     color((255,155,192))
  246.     penup()
  247.     goto(148,-155)
  248.     pendown()
  249.     setheading(0)
  250.     #打卷的尾巴
  251.     circle(70,20)
  252.     circle(10,330)
  253.     circle(70,30)

  254. def setting():          #参数设置
  255.     #设置窗口大小
  256.     setup(800,500)
  257.     #设置画笔
  258.     pensize(4)
  259.     hideturtle()
  260.     colormode(255)
  261.     speed(0)
  262.    
  263. def main():
  264.     setting()           #画布、画笔设置
  265.     nose()              #鼻子
  266.     head()              #头
  267.     ears()              #耳朵
  268.     eyes()              #眼睛
  269.     cheek()             #腮
  270.     mouth()             #嘴
  271.     body()              #身体
  272.     hands()             #手
  273.     feet()              #脚
  274.     tail()             #尾巴
  275.     done()             #设置窗口不关闭
  276. if __name__ == "__main__":
  277.     main()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2025-7-23 21:54:39 | 显示全部楼层
哈哈哈,高低也附上截图嘛?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2025-7-23 21:55:31 | 显示全部楼层
好厉害
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2025-7-23 21:56:03 | 显示全部楼层
小甲鱼的二师兄 发表于 2025-7-23 21:54
哈哈哈,高低也附上截图嘛?

居然是一模一样哈哈哈

微信截图_20250723215520.png

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2025-7-25 11:43:24 | 显示全部楼层
哈哈哈哈哈哈哈哈
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-9-10 19:45

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表