首页 > 其他分享 >升级版皮卡丘

升级版皮卡丘

时间:2023-12-02 16:44:06浏览次数:39  
标签:begin goto self circle noTrace 皮卡丘 升级版 fill

import turtle

def getPosition(x, y):

    turtle.setx(x)

    turtle.sety(y)

    print(x, y)

class Pikachu:

    def __init__(self):

        self.t = turtle.Turtle()

        t = self.t

        t.pensize(3)

        t.speed(9)

        t.ondrag(getPosition)

    def noTrace_goto(self, x, y):

        self.t.penup()

        self.t.goto(x, y)

        self.t.pendown()

    def leftEye(self, x, y):

        self.noTrace_goto(x, y)

        t = self.t

        t.seth(0)

        t.fillcolor('#333333')

        t.begin_fill()

        t.circle(22)

        t.end_fill()

        self.noTrace_goto(x, y + 10)

        t.fillcolor('#000000')

        t.begin_fill()

        t.circle(10)

        t.end_fill()

        self.noTrace_goto(x + 6, y + 22)

        t.fillcolor('#ffffff')

        t.begin_fill()

        t.circle(10)

        t.end_fill()

    def rightEye(self, x, y):

        self.noTrace_goto(x, y)

        t = self.t

        t.seth(0)

        t.fillcolor('#333333')

        t.begin_fill()

        t.circle(22)

        t.end_fill()

        self.noTrace_goto(x, y + 10)

        t.fillcolor('#000000')

        t.begin_fill()

        t.circle(10)

        t.end_fill()

        self.noTrace_goto(x - 6, y + 22)

        t.fillcolor('#ffffff')

        t.begin_fill()

        t.circle(10)

        t.end_fill()

    def mouth(self, x, y):

        self.noTrace_goto(x, y)

        t = self.t

        t.fillcolor('#88141D')

        t.begin_fill()

        # 下嘴唇

        l1 = []

        l2 = []

        t.seth(190)

        a = 0.7

        for i in range(28):

            a += 0.1

            t.right(3)

            t.fd(a)

            l1.append(t.position())

        self.noTrace_goto(x, y)

        t.seth(10)

        a = 0.7

        for i in range(28):

            a += 0.1

            t.left(3)

            t.fd(a)

            l2.append(t.position())

        # 上嘴唇

        t.seth(10)

        t.circle(50, 15)

        t.left(180)

        t.circle(-50, 15)

        t.circle(-50, 40)

        t.seth(233)

        t.circle(-50, 55)

        t.left(180)

        t.circle(50, 12.1)

        t.end_fill()

        # 舌头

        self.noTrace_goto(17, 54)

        t.fillcolor('#DD716F')

        t.begin_fill()

        t.seth(145)

        t.circle(40, 86)

        t.penup()

        for pos in reversed(l1[:20]):

            t.goto(pos[0], pos[1] + 1.5)

        for pos in l2[:20]:

            t.goto(pos[0], pos[1] + 1.5)

        t.pendown()

        t.end_fill()

        # 鼻子

        self.noTrace_goto(-17, 94)

        t.seth(8)

        t.fd(4)

        t.back(8)

    # 红脸颊

    def leftCheek(self, x, y):

        turtle.tracer(False)

        t = self.t

        self.noTrace_goto(x, y)

        t.seth(300)

        t.fillcolor('#DD4D28')

        t.begin_fill()

        a = 2.3

        for i in range(120):

            if 0 <= i < 30 or 60 <= i < 90:

                a -= 0.05

                t.lt(3)

                t.fd(a)

            else:

                a += 0.05

                t.lt(3)

                t.fd(a)

        t.end_fill()

        turtle.tracer(True)

    def rightCheek(self, x, y):

        t = self.t

        turtle.tracer(False)

        self.noTrace_goto(x, y)

        t.seth(60)

        t.fillcolor('#DD4D28')

        t.begin_fill()

        a = 2.3

        for i in range(120):

            if 0 <= i < 30 or 60 <= i < 90:

                a -= 0.05

                t.lt(3)

                t.fd(a)

            else:

                a += 0.05

                t.lt(3)

                t.fd(a)

        t.end_fill()

        turtle.tracer(True)

    def colorLeftEar(self, x, y):

        t = self.t

        self.noTrace_goto(x, y)

        t.fillcolor('#000000')

        t.begin_fill()

        t.seth(330)

        t.circle(100, 35)

        t.seth(219)

        t.circle(-300, 19)

        t.seth(110)

        t.circle(-30, 50)

        t.circle(-300, 10)

        t.end_fill()

    def colorRightEar(self, x, y):

        t = self.t

        self.noTrace_goto(x, y)

        t.fillcolor('#000000')

        t.begin_fill()

        t.seth(300)

        t.circle(-100, 30)

        t.seth(35)

        t.circle(300, 15)

        t.circle(30, 50)

        t.seth(190)

        t.circle(300, 17)

        t.end_fill()

    def body(self):

        t = self.t

        t.fillcolor('#F6D02F')

        t.begin_fill()

        # 右脸轮廓

        t.penup()

        t.circle(130, 40)

        t.pendown()

        t.circle(100, 105)

        t.left(180)

        t.circle(-100, 5)

        # 右耳朵

        t.seth(20)

        t.circle(300, 30)

        t.circle(30, 50)

        t.seth(190)

        t.circle(300, 36)

        # 上轮廓

        t.seth(150)

        t.circle(150, 70)

        # 左耳朵

        t.seth(200)

        t.circle(300, 40)

        t.circle(30, 50)

        t.seth(20)

        t.circle(300, 35)

        # print(t.pos())

        # 左脸轮廓

        t.seth(240)

        t.circle(105, 95)

        t.left(180)

        t.circle(-105, 5)

        # 左手

        t.seth(210)

        t.circle(500, 18)

        t.seth(200)

        t.fd(10)

        t.seth(280)

        t.fd(7)

        t.seth(210)

        t.fd(10)

        t.seth(300)

        t.circle(10, 80)

        t.seth(220)

        t.fd(10)

        t.seth(300)

        t.circle(10, 80)

        t.seth(240)

        t.fd(12)

        t.seth(0)

        t.fd(13)

        t.seth(240)

        t.circle(10, 70)

        t.seth(10)

        t.circle(10, 70)

        t.seth(10)

        t.circle(300, 18)

        t.seth(75)

        t.circle(500, 8)

        t.left(180)

        t.circle(-500, 15)

        t.seth(250)

        t.circle(100, 65)

        # 左脚

        t.seth(320)

        t.circle(100, 5)

        t.left(180)

        t.circle(-100, 5)

        t.seth(220)

        t.circle(200, 20)

        t.circle(20, 70)

        t.seth(60)

        t.circle(-100, 20)

        t.left(180)

        t.circle(100, 20)

        t.seth(300)

        t.circle(10, 70)

        t.seth(60)

        t.circle(-100, 20)

        t.left(180)

        t.circle(100, 20)

        t.seth(10)

        t.circle(100, 60)

        # 横向

        t.seth(180)

        t.circle(-100, 10)

        t.left(180)

        t.circle(100, 10)

        t.seth(5)

        t.circle(100, 10)

        t.circle(-100, 40)

        t.circle(100, 35)

        t.left(180)

        t.circle(-100, 10)

        # 右脚

        t.seth(290)

        t.circle(100, 55)

        t.circle(10, 50)

        t.seth(120)

        t.circle(100, 20)

        t.left(180)

        t.circle(-100, 20)

        t.seth(0)

        t.circle(10, 50)

        t.seth(110)

        t.circle(100, 20)

        t.left(180)

        t.circle(-100, 20)

        t.seth(30)

        t.circle(20, 50)

        t.seth(100)

        t.circle(100, 40)

        # 右侧身体轮廓

        t.seth(200)

        t.circle(-100, 5)

        t.left(180)

        t.circle(100, 5)

        t.left(30)

        t.circle(100, 75)

        t.right(15)

        t.circle(-300, 21)

        t.left(180)

        t.circle(300, 3)

        # 右手

        t.seth(43)

        t.circle(200, 60)

        t.right(10)

        t.fd(10)

        t.circle(5, 160)

        t.seth(90)

        t.circle(5, 160)

        t.seth(90)

        t.fd(10)

        t.seth(90)

        t.circle(5, 180)

        t.fd(10)

        t.left(180)

        t.left(20)

        t.fd(10)

        t.circle(5, 170)

        t.fd(10)

        t.seth(240)

        t.circle(50, 30)

        t.end_fill()

        self.noTrace_goto(130, 125)

        t.seth(-20)

        t.fd(5)

        t.circle(-5, 160)

        t.fd(5)

        # 手指纹

        self.noTrace_goto(166, 130)

        t.seth(-90)

        t.fd(3)

        t.circle(-4, 180)

        t.fd(3)

        t.seth(-90)

        t.fd(3)

        t.circle(-4, 180)

        t.fd(3)

        # 尾巴

        self.noTrace_goto(168, 134)

        t.fillcolor('#F6D02F')

        t.begin_fill()

        t.seth(40)

        t.fd(200)

        t.seth(-80)

        t.fd(150)

        t.seth(210)

        t.fd(150)

        t.left(90)

        t.fd(100)

        t.right(95)

        t.fd(100)

        t.left(110)

        t.fd(70)

        t.right(110)

        t.fd(80)

        t.left(110)

        t.fd(30)

        t.right(110)

        t.fd(32)

        t.right(106)

        t.circle(100, 25)

        t.right(15)

        t.circle(-300, 2)

        ##############

        # print(t.pos())

        t.seth(30)

        t.fd(40)

        t.left(100)

        t.fd(70)

        t.right(100)

        t.fd(80)

        t.left(100)

        t.fd(46)

        t.seth(66)

        t.circle(200, 38)

        t.right(10)

        t.fd(10)

        t.end_fill()

        # 尾巴花纹

        t.fillcolor('#923E24')

        self.noTrace_goto(126.82, -156.84)

        t.begin_fill()

        t.seth(30)

        t.fd(40)

        t.left(100)

        t.fd(40)

        t.pencolor('#923e24')

        t.seth(-30)

        t.fd(30)

        t.left(140)

        t.fd(20)

        t.right(150)

        t.fd(20)

        t.left(150)

        t.fd(20)

        t.right(150)

        t.fd(20)

        t.left(130)

        t.fd(18)

        t.pencolor('#000000')

        t.seth(-45)

        t.fd(67)

        t.right(110)

        t.fd(80)

        t.left(110)

        t.fd(30)

        t.right(110)

        t.fd(32)

        t.right(106)

        t.circle(100, 25)

        t.right(15)

        t.circle(-300, 2)

        t.end_fill()

        # 帽子、眼睛、嘴巴、脸颊

        self.cap(-134.07, 147.81)

        self.mouth(-5, 25)

        self.leftCheek(-126, 32)

        self.rightCheek(107, 63)

        self.colorLeftEar(-250, 100)

        self.colorRightEar(140, 270)

        self.leftEye(-85, 90)

        self.rightEye(50, 110)

        t.hideturtle()

    def cap(self, x, y):

        self.noTrace_goto(x, y)

        t = self.t

        t.fillcolor('#CD0000')

        t.begin_fill()

        t.seth(200)

        t.circle(400, 7)

        t.left(180)

        t.circle(-400, 30)

        t.circle(30, 60)

        t.fd(50)

        t.circle(30, 45)

        t.fd(60)

        t.left(5)

        t.circle(30, 70)

        t.right(20)

        t.circle(200, 70)

        t.circle(30, 60)

        t.fd(70)

        # print(t.pos())

        t.right(35)

        t.fd(50)

        t.circle(8, 100)

        t.end_fill()

        self.noTrace_goto(-168.47, 185.52)

        t.seth(36)

        t.circle(-270, 54)

        t.left(180)

        t.circle(270, 27)


        t.circle(-80, 98)

        t.fillcolor('#444444')

        t.begin_fill()

        t.left(180)

        t.circle(80, 197)

        t.left(58)

        t.circle(200, 45)

        t.end_fill()

        self.noTrace_goto(-58, 270)

        t.pencolor('#228B22')

        t.dot(35)

        self.noTrace_goto(-30, 280)

        t.fillcolor('#228B22')

        t.begin_fill()

        t.seth(100)

        t.circle(30, 180)

        t.seth(190)

        t.fd(15)

        t.seth(100)

        t.circle(-45, 180)

        t.right(90)

        t.fd(15)

        t.end_fill()

        t.pencolor('#000000')

    def start(self):

        self.body()

def main():

    print('Painting the Pikachu... ')

    turtle.screensize(800, 600)

    turtle.title('Pikachu')

    pikachu = Pikachu()

    pikachu.start()

    turtle.mainloop()

if __name__ == '__main__':

    main()

效果如

 

标签:begin,goto,self,circle,noTrace,皮卡丘,升级版,fill
From: https://www.cnblogs.com/boyeyuan/p/17871833.html

相关文章

  • 皮卡丘
    #!/usr/bin/envpython#-*-coding:utf-8-*-fromturtleimport*'''绘制皮卡丘头部'''defface(x,y):"""画脸"""begin_fill()penup()#将海龟移动到指定的坐标goto(x,y)pendown()#......
  • 用户登录注册升级版
    【一】需求介绍用户可以注册,并将注册信息临时保存起来,登陆时可根据指定用户名或密码进行登陆设定好用户名和密码,用户通过输入指定的用户名和密码进行登陆最大尝试次数:用户最多尝试猜测3次最大尝试次数后:如3次后,问用户是否继续登陆如果回答Y或y,就再给3次机会,提示【还......
  • Vue公共loading升级版(处理并发异步差时响应)
    公共loading是项目系统中很常见的场景,处理方式也不外乎三个步骤:1.通过全局状态管理定义状态值(vuex、pinia等)。2.在程序主入口监听状态值变化,从而展示/隐藏laoding动画。3.在请求和相应拦截器中变更状态值。第一二步骤处理大同小异,但在第三步中,网上很多博文分享的方法是:在请求......
  • Golang布隆过滤器升级版
    作用:平常使用的布隆过滤器可以用来过滤Redis空数据,避免缓存穿透。升级点:将原本的bool数组位更改为int数组,实现便于删除操作的场景。代码如下:packagemainimport( "fmt")//BloomFilter布隆过滤器typeBloomFilterstruct{ bitArray[]int//升级版结构哈希所落位置+......
  • 洛谷内卷监视工具(升级版)
    较原版内卷监视工具,增加了一下功能:计分板(宏观掌控他人的卷题数量和难度分布)多次连续AC相同题目去重可能会不定时更新有什么建议可以提出varuserlist=["ricky_lin","Query_Failed","The_Last_Candy","Jeefy","Rairn","hfjh","fsfdgdg","aish......
  • Redis队列升级版利用Spring项目BeanDefinition自动注入
    利用Redis实现队列先进先出队列:https://www.cnblogs.com/LiuFqiang/p/16366813.html延迟队列:https://www.cnblogs.com/LiuFqiang/p/16592522.html定长队列:https://www.cnblogs.com/LiuFqian/p/17372463.html在使用Redis做消息队列的时候,需要配置队列属性的bean,如果自己项目......
  • ActiveMQ升级版本操作
    ActiveMQ升级版本操作ActiveMQ依赖JDK版本MQ版本号Build-Jdkapache-activemq-5.10.01.7apache-activemq-5.11.01.7apache-activemq-5.12.01.7apache-activemq-5.13.01.7apache-activemq-5.14.01.7apache-activemq-5.15.01.8apache-activemq-......
  • 近百个最新免费chatgpt访问集合,包含国内直接访问和国外升级版本
    近百个最新免费chatgpt访问集合,包含国内直接访问和国外升级版本。ChatGPT是一个基于人工智能的聊天机器人,它可以与用户进行自然语言交互。ChatGPT使用了最新的自然语言处理技术,包括深度学习和神经网络,以便更好地理解用户的意图和回答用户的问题。ChatGPT可以回答各种问题,包括但不限......
  • JeecgBoot v3.5.5 版本发布,性能大升级版本—开源免费的低代码开发平台
    项目介绍JeecgBoot是一款企业级的低代码平台!前后端分离架构SpringBoot2.x,SpringCloud,AntDesign&Vue3,Mybatis-plus,Shiro,JWT支持微服务。强大的代码生成器让前后端代码一键生成!JeecgBoot引领低代码开发模式(OnlineCoding->代码生成->手工MERGE),帮助解决Java项目70%的重复......
  • 准确预测极端降水,哥伦比亚大学推出升级版神经网络 Org-NN
    内容一览:随着环境变化加剧,近年来全球极端天气现象频频出现,准确预测降水强度对人类以及自然环境都十分重要。传统模型预测降水的方差较小,偏向小雨,对极端降水预测不足。关键词:极端天气内隐学习神经网络:::hljs-center本文首发于HyperAI超神经微信公众平台~:::受台风「......