吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 19306|回复: 95
收起左侧

[Python 转载] python代码画小猪佩奇

  [复制链接]
Mr.番茄炒蛋 发表于 2019-2-15 15:45
本帖最后由 wushaominkk 于 2019-2-18 16:29 编辑

用python代码画小猪佩奇,一个动态的过程
[Python] 纯文本查看 复制代码
from turtle import*

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

    penup()
    setheading(90)
    forward(25)
    setheading(0)
    forward(10)
    pendown()
    pencolor(255,155,192)#画笔颜色
    setheading(10)
    begin_fill()
    circle(5)
    color(160,82,45)#返回或设置pencolor和fillcolor
    end_fill()

    penup()
    setheading(0)
    forward(20)
    pendown()
    pencolor(255,155,192)
    setheading(10)
    begin_fill()
    circle(5)
    color(160,82,45)
    end_fill()


def head(x,y):#头
    color((255,155,192),"pink")
    penup()
    goto(x,y)
    setheading(0)
    pendown()
    begin_fill()
    setheading(180)
    circle(300,-30)
    circle(100,-60)
    circle(80,-100)
    circle(150,-20)
    circle(60,-95)
    setheading(161)
    circle(-300,15)
    penup()
    goto(-100,100)
    pendown()
    setheading(-30)
    a=0.4
    for i in range(60):
        if 0<=i<30 or 60<=i<90:
            a=a+0.08
            lt(3) #向左转3度
            fd(a) #向前走a的步长
        else:
            a=a-0.08
            lt(3)
            fd(a)
    end_fill()


def ears(x,y): #耳朵
    color((255,155,192),"pink")
    penup()
    goto(x,y)
    pendown()
    begin_fill()
    setheading(100)
    circle(-50,50)
    circle(-10,120)
    circle(-50,54)
    end_fill()

    penup()
    setheading(90)
    forward(-12)
    setheading(0)
    forward(30)
    pendown()
    begin_fill()
    setheading(100)
    circle(-50,50)
    circle(-10,120)
    circle(-50,56)
    end_fill()


def eyes(x,y):#眼睛
    color((255,155,192),"white")
    penup()
    setheading(90)
    forward(-20)
    setheading(0)
    forward(-95)
    pendown()
    begin_fill()
    circle(15)
    end_fill()

    color("black")
    penup()
    setheading(90)
    forward(12)
    setheading(0)
    forward(-3)
    pendown()
    begin_fill()
    circle(3)
    end_fill()

    color((255,155,192),"white")
    penup()
    seth(90)
    forward(-25)
    seth(0)
    forward(40)
    pendown()
    begin_fill()
    circle(15)
    end_fill()

    color("black")
    penup()
    setheading(90)
    forward(12)
    setheading(0)
    forward(-3)
    pendown()
    begin_fill()
    circle(3)
    end_fill()


def cheek(x,y):#腮
    color((255,155,192))
    penup()
    goto(x,y)
    pendown()
    setheading(0)
    begin_fill()
    circle(30)
    end_fill()


def mouth(x,y): #嘴
    color(239,69,19)
    penup()
    goto(x,y)
    pendown()
    setheading(-80)
    circle(30,40)
    circle(40,80)

def body(x,y):#身体
    color("red",(255,99,71))
    penup()
    goto(x,y)
    pendown()
    begin_fill()
    setheading(-130)
    circle(100,10)
    circle(300,30)
    setheading(0)
    forward(230)
    setheading(90)
    circle(300,30)
    circle(100,3)
    color((255,155,192),(255,100,100))
    setheading(-135)
    circle(-80,63)
    circle(-150,24)
    end_fill()


def hands(x,y):#手
    color((255,155,192))
    penup()
    goto(x,y)
    pendown()
    setheading(-160)
    circle(300,15)
    penup()
    setheading(90)
    forward(15)
    setheading(0)
    forward(0)
    pendown()
    setheading(-10)
    circle(-20,90)

    penup()
    setheading(90)
    forward(30)
    setheading(0)
    forward(237)
    pendown()
    setheading(-20)
    circle(-300,15)
    penup()
    setheading(90)
    forward(20)
    setheading(0)
    forward(0)
    pendown()
    setheading(-170)
    circle(20,90)

def foot(x,y):#脚
    pensize(10)
    color((240,128,128))
    penup()
    goto(x,y)
    pendown()
    setheading(-90)
    forward(40)
    setheading(-180)
    color("black")
    pensize(15)
    fd(20)

    pensize(10)
    color((240,128,128))
    penup()
    setheading(90)
    forward(40)
    setheading(0)
    forward(90)
    pendown()
    setheading(-90)
    forward(40)
    setheading(-180)
    color("black")
    pensize(15)
    fd(20)

def tail(x,y):#尾巴
    pensize(4)
    color((255,155,192))
    penup()
    goto(x,y)
    pendown()
    seth(0)
    circle(70,20)
    circle(10,330)
    circle(70,30)

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

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

if __name__ == '__main__':
        main()

免费评分

参与人数 24吾爱币 +18 热心值 +18 收起 理由
asd4353111 + 1 + 1 谢谢@Thanks!
H-ideOnBush + 1 + 1 谢谢@Thanks!
hycyugi + 1 + 1 谢谢@Thanks!
s62585 + 1 热心回复!
透明色可乐 + 1 + 1 我很赞同!
冥界3大法王 + 1 用我汉化的Wing IDE 6.1测试了下效果还不错哟~~
zxj112613 + 1 + 1 我很赞同!
wangfeilong0317 + 1 谢谢@Thanks!
lin02993 + 1 + 1 用心讨论,共获提升!
zhangbice + 1 用心讨论,共获提升!
嘟鲁鲁 + 1 + 1 谢谢@Thanks!
RH + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
SOL7777777 + 1 谢谢@Thanks!
gwl518 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
苏紫方璇 + 3 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
博一笑 + 1 我很赞同!
小黑LLB + 1 拿去拿去,莫要跟我客气
吾爱支持 + 1 谢谢@Thanks!
NikoroX + 1 我很赞同!
hjdx001 + 1 + 1 代码运行成功,感谢楼主分享,1热心奉上
7lsu + 1 我在知乎上看到过一模一样的帖子,请问你的作者本人吗?
zl33333 + 1 谢谢@Thanks!
xian54966 + 1 + 1 我很赞同!
苏晓宇c + 1 ....助攻一下

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

mini5pusb 发表于 2019-3-14 21:46
RH 发表于 2019-3-14 16:17
python3 打开,在论坛复制的代码保存时候检查头部空白

我现在用的是python3.7.2版本的,用的是内置的 idle和shell,现在出现的错误提示是:invalid character in identifier,
QQ截图20190314213913.jpg
请问下要怎样解决?
hjdx001 发表于 2019-2-15 16:43
quifangde 发表于 2019-2-15 16:01
jcfszxc 发表于 2019-2-15 16:05
这是比较入门的海龟函数了
zl33333 发表于 2019-2-15 16:11
楼主能不能把所有代码都注释下啊
博一笑 发表于 2019-2-15 16:12
这是知乎上发的吧
While_Shark 发表于 2019-2-15 16:25
QQ截图20190215162450.jpg

感谢分享,这是楼主程序画出来的佩奇
嘟嘟侠 发表于 2019-2-15 16:49
优秀如你
sgh2zlx 发表于 2019-2-15 16:57 来自手机
棒           
吾爱支持 发表于 2019-2-15 18:38
感谢楼主分享源代码,收藏了,送上小心心和祝福……希望以后多分享……
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-16 15:36

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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