鱼C论坛

 找回密码
 立即注册
查看: 2237|回复: 7

[学习笔记] python画个小猪佩奇

[复制链接]
发表于 2020-4-1 08:20:09 | 显示全部楼层 |阅读模式

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

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

x
  1. # -*- coding:utf-8 -*-

  2. from turtle import *

  3. def nose(x,y):#鼻子
  4.     penup()#提起笔
  5.     goto(x,y)#定位
  6.     pendown()#落笔,开始画
  7.     setheading(-30)#将乌龟的方向设置为to_angle/为数字(0-东、90-北、180-西、270-南)
  8.     begin_fill()#准备开始填充图形
  9.     a=0.4
  10.     for i in range(120):
  11.         if 0<=i<30 or 60<=i<90:
  12.             a=a+0.08
  13.             left(3) #向左转3度
  14.             forward(a) #向前走a的步长
  15.         else:
  16.             a=a-0.08
  17.             left(3)
  18.             forward(a)
  19.     end_fill()#填充完成

  20.     penup()
  21.     setheading(90)
  22.     forward(25)
  23.     setheading(0)
  24.     forward(10)
  25.     pendown()
  26.     pencolor(255,155,192)#画笔颜色
  27.     setheading(10)
  28.     begin_fill()
  29.     circle(5)
  30.     color(160,82,45)#返回或设置pencolor和fillcolor
  31.     end_fill()

  32.     penup()
  33.     setheading(0)
  34.     forward(20)
  35.     pendown()
  36.     pencolor(255,155,192)
  37.     setheading(10)
  38.     begin_fill()
  39.     circle(5)
  40.     color(160,82,45)
  41.     end_fill()


  42. def head(x,y):#头
  43.     color((255,155,192),"pink")
  44.     penup()
  45.     goto(x,y)
  46.     setheading(0)
  47.     pendown()
  48.     begin_fill()
  49.     setheading(180)
  50.     circle(300,-30)
  51.     circle(100,-60)
  52.     circle(80,-100)
  53.     circle(150,-20)
  54.     circle(60,-95)
  55.     setheading(161)
  56.     circle(-300,15)
  57.     penup()
  58.     goto(-100,100)
  59.     pendown()
  60.     setheading(-30)
  61.     a=0.4
  62.     for i in range(60):
  63.         if 0<=i<30 or 60<=i<90:
  64.             a=a+0.08
  65.             lt(3) #向左转3度
  66.             fd(a) #向前走a的步长
  67.         else:
  68.             a=a-0.08
  69.             lt(3)
  70.             fd(a)
  71.     end_fill()


  72. def ears(x,y): #耳朵
  73.     color((255,155,192),"pink")
  74.     penup()
  75.     goto(x,y)
  76.     pendown()
  77.     begin_fill()
  78.     setheading(100)
  79.     circle(-50,50)
  80.     circle(-10,120)
  81.     circle(-50,54)
  82.     end_fill()

  83.     penup()
  84.     setheading(90)
  85.     forward(-12)
  86.     setheading(0)
  87.     forward(30)
  88.     pendown()
  89.     begin_fill()
  90.     setheading(100)
  91.     circle(-50,50)
  92.     circle(-10,120)
  93.     circle(-50,56)
  94.     end_fill()


  95. def eyes(x,y):#眼睛
  96.     color((255,155,192),"white")
  97.     penup()
  98.     setheading(90)
  99.     forward(-20)
  100.     setheading(0)
  101.     forward(-95)
  102.     pendown()
  103.     begin_fill()
  104.     circle(15)
  105.     end_fill()

  106.     color("black")
  107.     penup()
  108.     setheading(90)
  109.     forward(12)
  110.     setheading(0)
  111.     forward(-3)
  112.     pendown()
  113.     begin_fill()
  114.     circle(3)
  115.     end_fill()

  116.     color((255,155,192),"white")
  117.     penup()
  118.     seth(90)
  119.     forward(-25)
  120.     seth(0)
  121.     forward(40)
  122.     pendown()
  123.     begin_fill()
  124.     circle(15)
  125.     end_fill()

  126.     color("black")
  127.     penup()
  128.     setheading(90)
  129.     forward(12)
  130.     setheading(0)
  131.     forward(-3)
  132.     pendown()
  133.     begin_fill()
  134.     circle(3)
  135.     end_fill()


  136. def cheek(x,y):#腮
  137.     color((255,155,192))
  138.     penup()
  139.     goto(x,y)
  140.     pendown()
  141.     setheading(0)
  142.     begin_fill()
  143.     circle(30)
  144.     end_fill()


  145. def mouth(x,y): #嘴
  146.     color(239,69,19)
  147.     penup()
  148.     goto(x,y)
  149.     pendown()
  150.     setheading(-80)
  151.     circle(30,40)
  152.     circle(40,80)

  153. def body(x,y):#身体
  154.     color("red",(255,99,71))
  155.     penup()
  156.     goto(x,y)
  157.     pendown()
  158.     begin_fill()
  159.     setheading(-130)
  160.     circle(100,10)
  161.     circle(300,30)
  162.     setheading(0)
  163.     forward(230)
  164.     setheading(90)
  165.     circle(300,30)
  166.     circle(100,3)
  167.     color((255,155,192),(255,100,100))
  168.     setheading(-135)
  169.     circle(-80,63)
  170.     circle(-150,24)
  171.     end_fill()


  172. def hands(x,y):#手
  173.     color((255,155,192))
  174.     penup()
  175.     goto(x,y)
  176.     pendown()
  177.     setheading(-160)
  178.     circle(300,15)
  179.     penup()
  180.     setheading(90)
  181.     forward(15)
  182.     setheading(0)
  183.     forward(0)
  184.     pendown()
  185.     setheading(-10)
  186.     circle(-20,90)

  187.     penup()
  188.     setheading(90)
  189.     forward(30)
  190.     setheading(0)
  191.     forward(237)
  192.     pendown()
  193.     setheading(-20)
  194.     circle(-300,15)
  195.     penup()
  196.     setheading(90)
  197.     forward(20)
  198.     setheading(0)
  199.     forward(0)
  200.     pendown()
  201.     setheading(-170)
  202.     circle(20,90)

  203. def foot(x,y):#脚
  204.     pensize(10)
  205.     color((240,128,128))
  206.     penup()
  207.     goto(x,y)
  208.     pendown()
  209.     setheading(-90)
  210.     forward(40)
  211.     setheading(-180)
  212.     color("black")
  213.     pensize(15)
  214.     fd(20)

  215.     pensize(10)
  216.     color((240,128,128))
  217.     penup()
  218.     setheading(90)
  219.     forward(40)
  220.     setheading(0)
  221.     forward(90)
  222.     pendown()
  223.     setheading(-90)
  224.     forward(40)
  225.     setheading(-180)
  226.     color("black")
  227.     pensize(15)
  228.     fd(20)

  229. def tail(x,y):#尾巴
  230.     pensize(4)
  231.     color((255,155,192))
  232.     penup()
  233.     goto(x,y)
  234.     pendown()
  235.     seth(0)
  236.     circle(70,20)
  237.     circle(10,330)
  238.     circle(70,30)

  239. def setting():          #参数设置
  240.     pensize(4)
  241.     hideturtle()        #使乌龟无形(隐藏)
  242.     colormode(255)      #将其设置为1.0或255.随后 颜色三元组的r,g,b值必须在0 .. cmode范围内
  243.     color((255,155,192),"pink")
  244.     setup(840,500)
  245.     speed(10)

  246. def main():
  247.     setting()           #画布、画笔设置
  248.     nose(-100,100)      #鼻子
  249.     head(-69,167)       #头
  250.     ears(0,160)         #耳朵
  251.     eyes(0,140)         #眼睛
  252.     cheek(80,10)        #腮
  253.     mouth(-20,30)       #嘴
  254.     body(-32,-8)        #身体
  255.     hands(-56,-45)      #手
  256.     foot(2,-177)        #脚
  257.     tail(148,-155)      #尾巴
  258.     done()

  259. if __name__ == '__main__':
  260.     main()
复制代码

评分

参与人数 1荣誉 +1 鱼币 +1 收起 理由
老八秘制 + 1 + 1 鱼C有你更精彩^_^

查看全部评分

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

使用道具 举报

发表于 2020-4-1 08:28:14 | 显示全部楼层
这个我好像发过了吖
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-1 08:38:14 | 显示全部楼层
要求配图片!!!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-1 08:39:45 | 显示全部楼层
WangJS 发表于 2020-4-1 08:38
要求配图片!!!

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

使用道具 举报

发表于 2020-4-1 08:43:13 | 显示全部楼层

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

使用道具 举报

发表于 2020-4-1 08:46:30 | 显示全部楼层

哈哈,你复制代码试一下呗
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-1 10:01:57 | 显示全部楼层
这里有图吖

图片

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

使用道具 举报

发表于 2020-4-1 10:30:58 | 显示全部楼层
我好想在互谅网上看过
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-4-30 18:03

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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