温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么使用python画皮卡丘

发布时间:2021-04-28 14:09:35 阅读:303 作者:小新 栏目:编程语言

这篇文章主要介绍怎么使用python画皮卡丘,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

python的数据类型有哪些?

python的数据类型:1. 数字类型,包括int(整型)、long(长整型)和float(浮点型)。2.字符串,分别是str类型和unicode类型。3.布尔型,Python布尔类型也是用于逻辑运算,有两个值:True(真)和False(假)。4.列表,列表是Python中使用最频繁的数据类型,集合中可以放任何数据类型。5. 元组,元组用”()”标识,内部元素用逗号隔开。6. 字典,字典是一种键值对的集合。7. 集合,集合是一个无序的、不重复的数据组合。

作为童年时代比较受大家欢迎的卡通人物,皮卡丘肯定是榜上有名的。我们在学习了python后,也可以使用相关的代码画出一只可爱的皮卡丘。

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(5015)
        t.left(180)
        t.circle(-5015)
 
        t.circle(-5040)
        t.seth(233)
        t.circle(-5055)
        t.left(180)
        t.circle(5012.1)
        t.end_fill()
 
        # 舌头
        self.noTrace_goto(1754)
        t.fillcolor('#DD716F')
        t.begin_fill()
        t.seth(145)
        t.circle(4086)
        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(-1794)
        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(10035)
        t.seth(219)
        t.circle(-30019)
        t.seth(110)
        t.circle(-3050)
        t.circle(-30010)
        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(-10030)
        t.seth(35)
        t.circle(30015)
        t.circle(3050)
        t.seth(190)
        t.circle(30017)
        t.end_fill()
 
    def body(self):
        t = self.t
 
        t.fillcolor('#F6D02F')
        t.begin_fill()
        # 右脸轮廓
        t.penup()
        t.circle(13040)
        t.pendown()
        t.circle(100105)
        t.left(180)
        t.circle(-1005)
 
        # 右耳朵
        t.seth(20)
        t.circle(30030)
        t.circle(3050)
        t.seth(190)
        t.circle(30036)
 
        # 上轮廓
        t.seth(150)
        t.circle(15070)
 
        # 左耳朵
        t.seth(200)
        t.circle(30040)
        t.circle(3050)
        t.seth(20)
        t.circle(30035)
        # print(t.pos())
 
        # 左脸轮廓
        t.seth(240)
        t.circle(10595)
        t.left(180)
        t.circle(-1055)
 
        # 左手
        t.seth(210)
        t.circle(50018)
        t.seth(200)
        t.fd(10)
        t.seth(280)
        t.fd(7)
        t.seth(210)
        t.fd(10)
        t.seth(300)
        t.circle(1080)
        t.seth(220)
        t.fd(10)
        t.seth(300)
        t.circle(1080)
        t.seth(240)
        t.fd(12)
        t.seth(0)
        t.fd(13)
        t.seth(240)
        t.circle(1070)
        t.seth(10)
        t.circle(1070)
        t.seth(10)
        t.circle(30018)
 
        t.seth(75)
        t.circle(5008)
        t.left(180)
        t.circle(-50015)
        t.seth(250)
        t.circle(10065)
 
        # 左脚
        t.seth(320)
        t.circle(1005)
        t.left(180)
        t.circle(-1005)
        t.seth(220)
        t.circle(20020)
        t.circle(2070)
 
        t.seth(60)
        t.circle(-10020)
        t.left(180)
        t.circle(10020)
        t.seth(300)
        t.circle(1070)
 
        t.seth(60)
        t.circle(-10020)
        t.left(180)
        t.circle(10020)
        t.seth(10)
        t.circle(10060)
 
        # 横向
        t.seth(180)
        t.circle(-10010)
        t.left(180)
        t.circle(10010)
        t.seth(5)
        t.circle(10010)
        t.circle(-10040)
        t.circle(10035)
        t.left(180)
        t.circle(-10010)
 
        # 右脚
        t.seth(290)
        t.circle(10055)
        t.circle(1050)
 
        t.seth(120)
        t.circle(10020)
        t.left(180)
        t.circle(-10020)
 
        t.seth(0)
        t.circle(1050)
 
        t.seth(110)
        t.circle(10020)
        t.left(180)
        t.circle(-10020)
 
        t.seth(30)
        t.circle(2050)
 
        t.seth(100)
        t.circle(10040)
 
        # 右侧身体轮廓
        t.seth(200)
        t.circle(-1005)
        t.left(180)
        t.circle(1005)
        t.left(30)
        t.circle(10075)
        t.right(15)
        t.circle(-30021)
        t.left(180)
        t.circle(3003)
 
        # 右手
        t.seth(43)
        t.circle(20060)
 
        t.right(10)
        t.fd(10)
 
        t.circle(5160)
        t.seth(90)
        t.circle(5160)
        t.seth(90)
 
        t.fd(10)
        t.seth(90)
        t.circle(5180)
        t.fd(10)
 
        t.left(180)
        t.left(20)
        t.fd(10)
        t.circle(5170)
        t.fd(10)
        t.seth(240)
        t.circle(5030)
 
        t.end_fill()
        self.noTrace_goto(130125)
        t.seth(-20)
        t.fd(5)
        t.circle(-5160)
        t.fd(5)
 
        # 手指纹
        self.noTrace_goto(166130)
        t.seth(-90)
        t.fd(3)
        t.circle(-4180)
        t.fd(3)
        t.seth(-90)
        t.fd(3)
        t.circle(-4180)
        t.fd(3)
 
        # 尾巴
        self.noTrace_goto(168134)
        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(10025)
        t.right(15)
        t.circle(-3002)
        ##############
        # 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(20038)
        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(10025)
        t.right(15)
        t.circle(-3002)
        t.end_fill()
 
        # 帽子、眼睛、嘴巴、脸颊
        self.cap(-134.07147.81)
        self.mouth(-525)
        self.leftCheek(-12632)
        self.rightCheek(10763)
        self.colorLeftEar(-250100)
        self.colorRightEar(140270)
        self.leftEye(-8590)
        self.rightEye(50110)
        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(4007)
        t.left(180)
        t.circle(-40030)
        t.circle(3060)
        t.fd(50)
        t.circle(3045)
        t.fd(60)
        t.left(5)
        t.circle(3070)
        t.right(20)
        t.circle(20070)
        t.circle(3060)
        t.fd(70)
        # print(t.pos())
        t.right(35)
        t.fd(50)
        t.circle(8100)
        t.end_fill()
        self.noTrace_goto(-168.47185.52)
        t.seth(36)
        t.circle(-27054)
        t.left(180)
        t.circle(27027)
        t.circle(-8098)
 
        t.fillcolor('#444444')
        t.begin_fill()
        t.left(180)
        t.circle(80197)
        t.left(58)
        t.circle(20045)
        t.end_fill()
 
        self.noTrace_goto(-58270)
        t.pencolor('#228B22')
        t.dot(35)
 
        self.noTrace_goto(-30280)
        t.fillcolor('#228B22')
        t.begin_fill()
        t.seth(100)
        t.circle(30180)
        t.seth(190)
        t.fd(15)
        t.seth(100)
        t.circle(-45180)
        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(800600)
    turtle.title('Pikachu')
    pikachu = Pikachu()
    pikachu.start()
    turtle.mainloop()
 
 
if __name__ == '__main__':
main()

怎么使用python画皮卡丘

以上是“怎么使用python画皮卡丘”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI