zoukankan      html  css  js  c++  java
  • python画小猪佩奇

      1 import turtle as t
      2  
      3  
      4 def init_pen():
      5     '''
      6     初始化画笔的一些属性
      7     '''
      8     t.pensize(4)  # 设置画笔的大小
      9     t.colormode(255)  # 设置GBK颜色范围为0-255
     10     t.color((255, 155, 192), "pink")  # 设置画笔颜色和填充颜色(pink)
     11     t.setup(900, 500)  # 设置主窗口的大小为900*500
     12     t.speed(10)  # 设置画笔速度为10
     13  
     14  
     15 def norse():
     16     '''
     17     鼻子
     18     '''
     19     t.pu()  # 提笔
     20     t.goto(-100, 100)  # 画笔前往坐标(-100,100)
     21     t.pd()  # 下笔
     22     t.seth(-30)  # 笔的角度为-30°
     23     t.begin_fill()  # 外形填充的开始标志
     24     a = 0.4
     25     for i in range(120):
     26         if 0 <= i < 30 or 60 <= i < 90:
     27             a = a + 0.08
     28             t.lt(3)  # 向左转3度
     29             t.fd(a)  # 向前走a的步长
     30         else:
     31             a = a - 0.08
     32             t.lt(3)
     33             t.fd(a)
     34     t.end_fill()  # 依据轮廓填充
     35     t.pu()  # 提笔
     36     t.seth(90)  # 笔的角度为90度
     37     t.fd(25)  # 向前移动25
     38     t.seth(0)  # 转换画笔的角度为0
     39     t.fd(10)
     40     t.pd()
     41     t.pencolor(255, 155, 192)  # 设置画笔颜色
     42     t.seth(10)
     43     t.begin_fill()
     44     t.circle(5)  # 画一个半径为5的圆
     45     t.color(160, 82, 45)  # 设置画笔和填充颜色
     46     t.end_fill()
     47     t.pu()
     48     t.seth(0)
     49     t.fd(20)
     50     t.pd()
     51     t.pencolor(255, 155, 192)
     52     t.seth(10)
     53     t.begin_fill()
     54     t.circle(5)
     55     t.color(160, 82, 45)
     56     t.end_fill()
     57  
     58  
     59 def head():
     60     '''
     61  62     '''
     63     t.color((255, 155, 192), "pink")
     64     t.pu()
     65     t.seth(90)
     66     t.fd(41)
     67     t.seth(0)
     68     t.fd(0)
     69     t.pd()
     70     t.begin_fill()
     71     t.seth(180)
     72     t.circle(300, -30)  # 顺时针画一个半径为300,圆心角为30°的园
     73     t.circle(100, -60)
     74     t.circle(80, -100)
     75     t.circle(150, -20)
     76     t.circle(60, -95)
     77     t.seth(161)
     78     t.circle(-300, 15)
     79     t.pu()
     80     t.goto(-100, 100)
     81     t.pd()
     82     t.seth(-30)
     83     a = 0.4
     84     for i in range(60):
     85         if 0 <= i < 30 or 60 <= i < 90:
     86             a = a + 0.08
     87             t.lt(3)  # 向左转3度
     88             t.fd(a)  # 向前走a的步长
     89         else:
     90             a = a - 0.08
     91             t.lt(3)
     92             t.fd(a)
     93     t.end_fill()
     94     import turtle
     95     turtle.write("何娃",align="left",font=("Arial",25,"normal"))
     96  
     97 
     98  
     99  
    100 def ear():
    101     '''
    102     耳朵
    103     '''
    104     t.color((255, 155, 192), "pink")
    105     t.pu()
    106     t.seth(90)
    107     t.fd(-7)
    108     t.seth(0)
    109     t.fd(70)
    110     t.pd()
    111     t.begin_fill()
    112     t.seth(100)
    113     t.circle(-50, 50)
    114     t.circle(-10, 120)
    115     t.circle(-50, 54)
    116     t.end_fill()
    117     t.pu()
    118     t.seth(90)
    119     t.fd(-12)
    120     t.seth(0)
    121     t.fd(30)
    122     t.pd()
    123     t.begin_fill()
    124     t.seth(100)
    125     t.circle(-50, 50)
    126     t.circle(-10, 120)
    127     t.circle(-50, 56)
    128     t.end_fill()
    129  
    130  
    131 def eye():
    132     '''
    133     眼睛
    134     '''
    135     t.color((255, 155, 192), "white")
    136     t.pu()
    137     t.seth(90)
    138     t.fd(-20)
    139     t.seth(0)
    140     t.fd(-95)
    141     t.pd()
    142     t.begin_fill()
    143     t.circle(15)
    144     t.end_fill()
    145     t.color("black")
    146     t.pu()
    147     t.seth(90)
    148     t.fd(12)
    149     t.seth(0)
    150     t.fd(-3)
    151     t.pd()
    152     t.begin_fill()
    153     t.circle(3)
    154     t.end_fill()
    155     t.color((255, 155, 192), "white")
    156     t.pu()
    157     t.seth(90)
    158     t.fd(-25)
    159     t.seth(0)
    160     t.fd(40)
    161     t.pd()
    162     t.begin_fill()
    163     t.circle(15)
    164     t.end_fill()
    165     t.color("black")
    166     t.pu()
    167     t.seth(90)
    168     t.fd(12)
    169     t.seth(0)
    170     t.fd(-3)
    171     t.pd()
    172     t.begin_fill()
    173     t.circle(3)
    174     t.end_fill()
    175  
    176  
    177 def blusher():
    178     '''
    179 180     '''
    181     t.color((255, 155, 192))
    182     t.pu()
    183     t.seth(90)
    184     t.fd(-95)
    185     t.seth(0)
    186     t.fd(65)
    187     t.pd()
    188     t.begin_fill()
    189     t.circle(30)
    190     t.end_fill()
    191  
    192  
    193 def mouth():
    194     '''
    195 196     '''
    197     t.color(239, 69, 19)
    198     t.pu()
    199     t.seth(90)
    200     t.fd(15)
    201     t.seth(0)
    202     t.fd(-100)
    203     t.pd()
    204     t.seth(-80)
    205     t.circle(30, 40)
    206     t.circle(40, 80)
    207  
    208  
    209 def body():
    210     '''
    211     身体
    212     '''
    213     t.color("red", (255, 99, 71))
    214     t.pu()
    215     t.seth(90)
    216     t.fd(-20)
    217     t.seth(0)
    218     t.fd(-78)
    219     t.pd()
    220     t.begin_fill()
    221     t.seth(-130)
    222     t.circle(100, 10)
    223     t.circle(300, 30)
    224     t.seth(0)
    225     t.fd(230)
    226     t.seth(90)
    227     t.circle(300, 30)
    228     t.circle(100, 3)
    229     t.color((255, 155, 192), (255, 100, 100))
    230     t.seth(-135)
    231     t.circle(-80, 63)
    232     t.circle(-150, 24)
    233     t.end_fill()
    234  
    235  
    236 def hand():
    237     '''
    238 239     '''
    240     t.color((255, 155, 192))
    241     t.pu()
    242     t.seth(90)
    243     t.fd(-40)
    244     t.seth(0)
    245     t.fd(-27)
    246     t.pd()
    247     t.seth(-160)
    248     t.circle(300, 15)
    249     t.pu()
    250     t.seth(90)
    251     t.fd(15)
    252     t.seth(0)
    253     t.fd(0)
    254     t.pd()
    255     t.seth(-10)
    256     t.circle(-20, 90)
    257     t.pu()
    258     t.seth(90)
    259     t.fd(30)
    260     t.seth(0)
    261     t.fd(237)
    262     t.pd()
    263     t.seth(-20)
    264     t.circle(-300, 15)
    265     t.pu()
    266     t.seth(90)
    267     t.fd(20)
    268     t.seth(0)
    269     t.fd(0)
    270     t.pd()
    271     t.seth(-170)
    272     t.circle(20, 90)
    273  
    274  
    275 def foot():
    276     '''
    277 278     '''
    279     t.pensize(10)
    280     t.color((240, 128, 128))
    281     t.pu()
    282     t.seth(90)
    283     t.fd(-75)
    284     t.seth(0)
    285     t.fd(-180)
    286     t.pd()
    287     t.seth(-90)
    288     t.fd(40)
    289     t.seth(-180)
    290     t.color("black")
    291     t.pensize(15)
    292     t.fd(20)
    293     t.pensize(10)
    294     t.color((240, 128, 128))
    295     t.pu()
    296     t.seth(90)
    297     t.fd(40)
    298     t.seth(0)
    299     t.fd(90)
    300     t.pd()
    301     t.seth(-90)
    302     t.fd(40)
    303     t.seth(-180)
    304     t.color("black")
    305     t.pensize(15)
    306     t.fd(20)
    307  
    308  
    309 def tail():
    310     '''
    311     尾巴
    312     '''
    313     t.pensize(4)
    314     t.color((255, 155, 192))
    315     t.pu()
    316     t.seth(90)
    317     t.fd(70)
    318     t.seth(0)
    319     t.fd(95)
    320     t.pd()
    321     t.seth(0)327     init_pen()
    328     norse()
    329     head()
    330     ear()
    331     eye()
    332     blusher()
    333     mouth()
    334     body()
    335     hand()
    336     foot()
    337     tail()
    338  
    339  
    340 if __name__ == '__main__':
    341     main()
    342     # 能够停住画布,不至于迅速结束
    343     t.mainloop()

    效果图:

  • 相关阅读:
    [极客大挑战 2019]EasySQL CTF复现
    [极客大挑战 2019]Havefun (一起来撸猫) CTF复现
    一个简单漂亮的登录页面(前端)
    Python XPath的使用
    Python Requests的基本用法
    Linux配置jdk环境变量
    高性能 Java RPC 框架 Dubbo
    Zookeeper的配置文件及命令
    zookeeper怎么实现分布式锁
    Zookeeper-集群崩溃恢复
  • 原文地址:https://www.cnblogs.com/Zmanqing/p/13708066.html
Copyright © 2011-2022 走看看