最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

用python畫一只帥氣的皮卡丘

 更新時(shí)間:2022年01月13日 15:45:46   作者:一手代碼一手詩  
大家好,本篇文章主要講的是用python畫一只帥氣的皮卡丘,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下

驚呆了!python畫出全網(wǎng)最帥比卡丘_Python

沒錯(cuò),全網(wǎng)最帥的比卡丘在我這~~~

驚呆了!python畫出全網(wǎng)最帥比卡丘_ide_02

為了訪問 Python 庫,您需要將它導(dǎo)入到您的 Python 環(huán)境中,使用以下命令將其導(dǎo)入 turtle到您的 Python 腳本中。

import turtle

首先,讓我們創(chuàng)建一個(gè) Screen 實(shí)例。

wn = turtle.Screen()

現(xiàn)在,創(chuàng)建一個(gè) Turtle 實(shí)例。

self.t = turtle.Turtle()

讓我們將速度設(shè)置為 3 使用 speed 方法,這意味著皮卡丘不會(huì)只是出現(xiàn)在屏幕上,繪圖也會(huì)有一些動(dòng)畫。如果您想更改背景顏色,可以使用該 bgcolor 方法,默??認(rèn)為白色。您可以使用pensize 方法調(diào)整筆的粗細(xì) ,它會(huì)稍微加粗。ondrag 拖動(dòng) Turtle 將在屏幕上移動(dòng)它,從而產(chǎn)生手繪(如果筆已放下)。

t.pensize(3)
t.speed(9)
t.ondrag(getPosition)

現(xiàn)在讓我們看看這個(gè)程序中使用的一些常用方法:

Turtle(): 用于創(chuàng)建并返回一個(gè)新的海龜對象。

forward(value): 相對于指定的值,海龜向前移動(dòng)。

向后(值): 相對于指定的值,海龜向后移動(dòng)。

right(angle): 烏龜順時(shí)針轉(zhuǎn)動(dòng)。

left(angle): 海龜逆時(shí)針旋轉(zhuǎn)。

penup(): 撿起烏龜筆。

pendown(): 烏龜筆放下。

up(): 與 penup() 相同。

down(): 與 pendown() 相同。

color(顏色名稱): Turtle 筆的顏色發(fā)生變化。

fillcolor(顏色名稱): 用于填充特定形狀的顏色已更改。

標(biāo)題(): 返回當(dāng)前標(biāo)題。

position(): 返回當(dāng)前位置。

goto(x, y): 將海龜?shù)奈恢靡苿?dòng)到坐標(biāo) x, y。

end_fill(): 關(guān)閉多邊形后填充當(dāng)前填充顏色。

begin_fill(): 記住填充多邊形的起點(diǎn)。

dot(): 點(diǎn)留在當(dāng)前位置。

stamp(): 海龜形狀的印象留在當(dāng)前位置。

Shape(): 應(yīng)該是 – ‘turtle’, ‘classic’, ‘arrow’ 或 ‘circle’。

上代碼:

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()

        # Lower Lip
        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())

        # Upper Lip
        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()

        # Tongue
        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()

        # Nose
        self.noTrace_goto(-17, 94)
        t.seth(8)
        t.fd(4)
        t.back(8)

    # Red Cheeks
    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()
        # Right face contour
        t.penup()
        t.circle(130, 40)
        t.pendown()
        t.circle(100, 105)
        t.left(180)
        t.circle(-100, 5)

        # Right ear
        t.seth(20)
        t.circle(300, 30)
        t.circle(30, 50)
        t.seth(190)
        t.circle(300, 36)

        # Upper profile
        t.seth(150)
        t.circle(150, 70)

        # Left ear
        t.seth(200)
        t.circle(300, 40)
        t.circle(30, 50)
        t.seth(20)
        t.circle(300, 35)
        #print(t.pos())

        # Left face contour
        t.seth(240)
        t.circle(105, 95)
        t.left(180)
        t.circle(-105, 5)

        # Left hand
        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)

        # Left foot
        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)

        # Horizontal
        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)

        # Right foot
        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)

        # Right body contour
        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)

        # Right hand
        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)

        # Fingers
        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)

        # Tail
        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()

        # Tail Pattern
        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()

        # Hat, Eye, Mouth, Cheek
        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... ')
    wn = turtle.Screen()
    wn.setup(width=600, height=800)
    pikachu = Pikachu()
    pikachu.start()
    turtle.mainloop()


if __name__ == '__main__':
    main()

到此這篇關(guān)于用python畫一只帥氣的皮卡丘的文章就介紹到這了,更多相關(guān)python皮卡丘內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python中的“_args”和“__kwargs”用法詳解

    Python中的“_args”和“__kwargs”用法詳解

    *args 和 **kwargs 主要?于函數(shù)定義,你可以將不定數(shù)量的參數(shù)傳遞給?個(gè)函數(shù),這篇文章主要介紹了Python中的“_args”和“__kwargs”用法,需要的朋友可以參考下
    2023-01-01
  • Python+Pygame實(shí)戰(zhàn)之詩詞填空游戲的實(shí)現(xiàn)

    Python+Pygame實(shí)戰(zhàn)之詩詞填空游戲的實(shí)現(xiàn)

    成語接龍大家都玩過,但詩詞填空大家玩過嗎?把成語接龍變成填空題。難度可上漲了不止一個(gè)檔次呢!本文就來用Python和Pygame實(shí)現(xiàn)詩詞填空游戲,需要的可以參考一下
    2022-12-12
  • python網(wǎng)絡(luò)爬蟲精解之XPath的使用說明

    python網(wǎng)絡(luò)爬蟲精解之XPath的使用說明

    XPath 是一門在 XML 文檔中查找信息的語言。XPath 可用來在 XML 文檔中對元素和屬性進(jìn)行遍歷。XPath 是 W3C XSLT 標(biāo)準(zhǔn)的主要元素,并且 XQuery 和 XPointer 都構(gòu)建于 XPath 表達(dá)之上
    2021-09-09
  • 在多種情況/開發(fā)環(huán)境中運(yùn)行python腳本和代碼的技巧分享

    在多種情況/開發(fā)環(huán)境中運(yùn)行python腳本和代碼的技巧分享

    Python腳本或程序是包含可執(zhí)行Python代碼的文件,能夠運(yùn)行Python腳本和代碼可能是您作為Python開發(fā)人員所需的最重要的技能,在本教程中,您將學(xué)習(xí)一些運(yùn)行Python腳本和代碼的技術(shù),在每種情況下使用的技術(shù)將取決于您的環(huán)境、平臺(tái)、需求和技能
    2023-11-11
  • Python+Tableau廣東省人口普查可視化的實(shí)現(xiàn)

    Python+Tableau廣東省人口普查可視化的實(shí)現(xiàn)

    本文將結(jié)合實(shí)例代碼,介紹Python+Tableau廣東省人口普查可視化,第七次人口普查數(shù)據(jù)分析,繪制歷次人口普查人口數(shù)量變化圖,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-06-06
  • Python編程使用有限狀態(tài)機(jī)識(shí)別地址有效性

    Python編程使用有限狀態(tài)機(jī)識(shí)別地址有效性

    這篇文章主要介紹了Python編程中如何使用有限狀態(tài)機(jī)識(shí)別地址有效性,如何識(shí)別一個(gè)地址是否有效,確切的講,如何編程識(shí)別一個(gè)中國地址是否有效
    2021-09-09
  • Python Selenium參數(shù)配置方法解析

    Python Selenium參數(shù)配置方法解析

    這篇文章主要介紹了Python Selenium參數(shù)配置方法解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-01-01
  • Python在OpenCV里實(shí)現(xiàn)極坐標(biāo)變換功能

    Python在OpenCV里實(shí)現(xiàn)極坐標(biāo)變換功能

    這篇文章主要介紹了在OpenCV里實(shí)現(xiàn)極坐標(biāo)變換功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-09-09
  • python爬取微博評論的實(shí)例講解

    python爬取微博評論的實(shí)例講解

    在本篇文章里小編給大家整理的是一篇關(guān)于python爬取微博評論的實(shí)例講解,有興趣的朋友們可以學(xué)習(xí)下。
    2021-01-01
  • 對Tensorflow中權(quán)值和feature map的可視化詳解

    對Tensorflow中權(quán)值和feature map的可視化詳解

    今天小編就為大家分享一篇對Tensorflow中權(quán)值和feature map的可視化詳解,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-06-06

最新評論

满洲里市| 玛纳斯县| 吴川市| 丰县| 和硕县| 墨脱县| 徐州市| 双柏县| 桐柏县| 乌拉特中旗| 宜川县| 鲁山县| 乃东县| 庆元县| 左贡县| 曲周县| 牡丹江市| 遵义县| 女性| 宜州市| 江城| 胶州市| 同仁县| 松原市| 常山县| 海口市| 华蓥市| 雷山县| 曲靖市| 威远县| 荥经县| 彭州市| 阳山县| 奉节县| 安陆市| 虞城县| 长沙县| 分宜县| 库伦旗| 呈贡县| 曲阜市|