亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Python利用Turtle繪制哆啦A夢和小豬佩奇

 更新時間:2022年04月04日 09:50:16   作者:電力系統(tǒng)與算法之美  
turtle庫是python的基礎繪圖庫,經常被用來介紹編程知識的方法庫,是標準庫之一,利用turtle可以制作很多復雜的繪圖。本文將為大家介紹通過turtle庫繪制制哆啦A夢和小豬佩奇,感興趣的小伙伴可以學習一下

1.哆啦A夢

“只要把愿望系在竹竿上請求月亮女神,心愿便能達成”。我超喜歡這句話。

哆啦A夢的創(chuàng)造要追溯到1969年的某個截稿日,作者藤子·F·不二雄的家里突然闖進了一只小貓,雖然很快就要截稿了,但作者還是和小貓玩了起來,還替小貓撓虱子,而這一撓就是幾個小時。等作者發(fā)現(xiàn)時間不夠用的時候,已經來不及完成稿子。這時作者像熱鍋上的螞蟻走來走去,突然踢到了女兒的不倒翁玩具,于是作者靈光一現(xiàn),把貓的形象和不倒翁結合起來,就創(chuàng)造了哆啦A夢。

2.小豬佩奇

對比于國內的《喜羊羊與灰太狼》和《熊出沒》,我希望有一天喜羊羊被灰太狼燉了、熊大被光頭強一槍打中,然后直接賣到動物園。(哈哈哈......)可是這個想法一直沒實現(xiàn),有些失落。還是看小豬佩奇吧:

由英國E1 Kids于2004年5月31日發(fā)行首播后,其動畫片已于全球180個地區(qū)播放,現(xiàn)已播出6季;

中國中央電視臺少兒頻道也在熱播之中,極簡的動畫風格,幽默的對話語調,深具教育意義的故事情節(jié),不僅能讓學齡前兒童學習知識,更能讓小朋友們從小養(yǎng)成良好的生活習慣體驗生活,深受全球各地小朋友們以及其家長們的喜愛。

3.Python代碼實現(xiàn)(哆啦A夢)

import turtle as t
t.title('哆啦A夢')
# t.speed(5)
t.pensize(8)
t.hideturtle()
t.screensize(500, 500, bg='white')
 
"""貓臉"""
t.fillcolor('#00A1E8')
t.begin_fill()
t.circle(120)
t.end_fill()
t.pensize(3)
t.fillcolor('white')
t.begin_fill()
t.circle(100)
t.end_fill()
t.pu()
t.home()
t.goto(0, 134)
t.pd()
t.pensize(4)
t.fillcolor("#EA0014")
t.begin_fill()
t.circle(18)
t.end_fill()
t.pu()
t.goto(7, 155)
t.pensize(2)
t.color('white', 'white')
t.pd()
t.begin_fill()
t.circle(4)
t.end_fill()
t.pu()
t.goto(-30, 160)
t.pensize(4)
t.pd()
t.color('black', 'white')
t.begin_fill()
a = 0.4
for i in range(120):
    if 0 <= i < 30 or 60 <= i < 90:
        a = a + 0.08
        t.lt(3)  # 向左轉3度
        t.fd(a)  # 向前走a的步長
    else:
        a = a - 0.08
        t.lt(3)
        t.fd(a)
t.end_fill()
t.pu()
t.goto(30, 160)
t.pensize(4)
t.pd()
t.color('black', 'white')
t.begin_fill()
for i in range(120):
    if 0 <= i < 30 or 60 <= i < 90:
        a = a + 0.08
        t.lt(3)  # 向左轉3度
        t.fd(a)  # 向前走a的步長
    else:
        a = a - 0.08
        t.lt(3)
        t.fd(a)
t.end_fill()
t.pu()
t.goto(-38, 190)
t.pensize(8)
t.pd()
t.right(-30)
t.forward(15)
t.right(70)
t.forward(15)
t.pu()
t.goto(15, 185)
t.pensize(4)
t.pd()
t.color('black', 'black')
t.begin_fill()
t.circle(13)
t.end_fill()
t.pu()
t.goto(13, 190)
t.pensize(2)
t.pd()
t.color('white', 'white')
t.begin_fill()
t.circle(5)
t.end_fill()
t.pu()
t.home()
t.goto(0, 134)
t.pensize(4)
t.pencolor('black')
t.pd()
t.right(90)
t.forward(40)
t.pu()
t.home()
t.goto(0, 124)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(10)
t.forward(80)
t.pu()
t.home()
t.goto(0, 114)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(6)
t.forward(80)
t.pu()
t.home()
t.goto(0, 104)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(0)
t.forward(80)
"""左邊的胡子"""
t.pu()
t.home()
t.goto(0, 124)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(170)
t.forward(80)
t.pu()
t.home()
t.goto(0, 114)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(174)
t.forward(80)
t.pu()
t.home()
t.goto(0, 104)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(180)
t.forward(80)
t.pu()
t.goto(-70, 70)
t.pd()
t.color('black', 'red')
t.pensize(6)
t.seth(-60)
t.begin_fill()
t.circle(80, 40)
t.circle(80, 80)
t.end_fill()
t.pu()
t.home()
t.goto(-80, 70)
t.pd()
t.forward(160)
t.pu()
t.home()
t.goto(-50, 50)
t.pd()
t.pensize(1)
t.fillcolor("#eb6e1a")
t.seth(40)
t.begin_fill()
t.circle(-40, 40)
t.circle(-40, 40)
t.seth(40)
t.circle(-40, 40)
t.circle(-40, 40)
t.seth(220)
t.circle(-80, 40)
t.circle(-80, 40)
t.end_fill()
# 領帶
t.pu()
t.goto(-70, 12)
t.pensize(14)
t.pencolor('red')
t.pd()
t.seth(-20)
t.circle(200, 30)
t.circle(200, 10)
"""鈴鐺"""
t.pu()
t.goto(0, -46)
t.pd()
t.pensize(3)
t.color("black", '#f8d102')
t.begin_fill()
t.circle(25)
t.end_fill()
t.pu()
t.goto(-5, -40)
t.pd()
t.pensize(2)
t.color("black", '#79675d')
t.begin_fill()
t.circle(5)
t.end_fill()
t.pensize(3)
t.right(115)
t.forward(7)
t.mainloop()

4.Python代碼實現(xiàn)(小豬佩奇 )

 
import turtle
from turtle import *
turtle.title('小豬佩奇')
 
def nose(x,y):
    """畫鼻子"""
    pensize(5)
    pencolor((255, 155, 192))
    penup()
    # 將海龜移動到指定的坐標
    goto(x,y)
    pendown()
    # 設置海龜?shù)姆较颍?-東、90-北、180-西、270-南)
    setheading(-30)
    begin_fill()
    fillcolor(255, 192, 203)
    a = 0.4
    for i in range(120):
        if 0 <= i < 30 or 60 <= i <90:
            a = a + 0.08
            # 向左轉3度
            left(3)
            # 向前走
            forward(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)
    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(90)
    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):
    '''畫身體'''
    penup()
    goto(x,y)
    pencolor('red')
    fillcolor(250,106,106)
    pendown()
    begin_fill()
    setheading(-66)
    circle(-450,17)
    setheading(180)
    forward(185)
    setheading(85)
    circle(-450,17)
    end_fill()
    '''右手'''
    penup()
    goto(110,-45)
    pendown()
    pensize(8)
    pencolor(255, 192, 203)
    setheading(30)
    circle(-400,10)
    penup()
    goto(167,-5)
    pendown()
    setheading(-120)
    forward(20)
    left(100)
    forward(20)
    '''左手'''
    penup()
    goto(-25,-45)
    pendown()
    pencolor(255, 192, 203)
    setheading(150)
    circle(400,10)
    penup()
    goto(-78,-6)
    pendown()
    setheading(-60)
    forward(20)
    right(100)
    forward(20)
 
def feet1(x,y):
    pensize(7)
    pencolor(255, 192, 203)
    penup()
    goto(x,y)
    setheading(-90)
    pendown()
    forward(10)
    penup()
    goto(x-12,y-10)
    pendown()
    pencolor(238,201,0)
    fillcolor(238,230,132)
    begin_fill()
    setheading(0)
    forward(24)
    right(90)
    forward(36)
    right(90)
    forward(40)
    circle(-10,180)
    forward(16)
    left(90)
    forward(12)
    end_fill()
 
def feet2(x,y):
    pensize(7)
    pencolor(255, 192, 203)
    penup()
    goto(x,y)
    setheading(-90)
    pendown()
    forward(10)
    penup()
    goto(x-12,y-10)
    pendown()
    pencolor(238,201,0)
    fillcolor(238,230,132)
    begin_fill()
    setheading(0)
    forward(24)
    right(90)
    forward(36)
    right(90)
    forward(40)
    circle(-10,180)
    forward(16)
    left(90)
    forward(12)
    end_fill()
 
def tail(x,y):
    pensize(8)
    penup()
    goto(x,y)
    pendown()
    pencolor(255, 192, 203)
    setheading(-5)
    circle(30,100)
    circle(10,180)
    circle(20,150)
 
def backg(x):
    penup()
    goto(-420,x)
    setheading(0)
    fillcolor(50,205,50)
    begin_fill()
    forward(840)
    right(90)
    forward(300)
    right(90)
    forward(840)
    right(90)
    forward(300)
    end_fill()
    setheading(0)
    fillcolor(0,191,255)
    begin_fill()
    forward(840)
    left(90)
    forward(600)
    left(90)
    forward(840)
    left(90)
    forward(600)
    end_fill()
 
def cloude1(x, y):
    """畫云"""
    penup()
    goto(x,y)
    setheading(90)
    fillcolor(255,255,255)
    begin_fill()
    a = 0.4
    for i in range(120):
        if 0 <= i < 30 or 60 <= i <90:
            a = a + 0.14
            # 向左轉3度
            left(3)
            # 向前走
            forward(a)
        else:
            a = a - 0.15
            left(3)
            forward(a)
    end_fill()
 
def cloude2(x, y):
    """畫云"""
    penup()
    goto(x,y)
    setheading(90)
    fillcolor(255,255,255)
    begin_fill()
    a = 0.4
    for i in range(120):
        if 0 <= i < 30 or 60 <= i <90:
            a = a + 0.15
            # 向左轉3度
            left(3)
            # 向前走
            forward(a)
        else:
            a = a - 0.13
            left(3)
            forward(a)
    end_fill()
 
def setting():
    """設置參數(shù)"""
    pensize(5)
    # 隱藏海龜
    hideturtle()
    colormode(255)
    color((255, 155, 192), "pink")
    setup(840, 700)
    speed(10)
 
 
def main():
    """主函數(shù)"""
    
    setting() 
    backg(0)
    body(105,-20)
    nose(-100, 100)
    head(-69, 167)
    ears(0, 160)
    eyes(0, 140)
    cheek(80, 10)
    mouth(-20, 30)
    feet1(10,-150)
    feet2(90,-150)
    tail(130,-110)
    cloude1(-200,200)
    cloude2(300,300)
    done()
 
 
if __name__ == '__main__':
    main()

以上就是Python利用Turtle繪制哆啦A夢和小豬佩奇的詳細內容,更多關于Python哆啦A夢 小豬佩奇的資料請關注腳本之家其它相關文章!

相關文章

  • 盤點20個Python數(shù)據(jù)科學庫神器打造數(shù)據(jù)魔法世界

    盤點20個Python數(shù)據(jù)科學庫神器打造數(shù)據(jù)魔法世界

    數(shù)據(jù)科學家和分析師常常使用?Python?來處理數(shù)據(jù)、進行分析和可視化,Python生態(tài)系統(tǒng)中有許多庫,但有一些庫是數(shù)據(jù)科學家日常工作中必不可少的,本文將深入介紹20個重要的Python?庫,包括示例代碼和用例
    2024-01-01
  • python通過urllib2爬網頁上種子下載示例

    python通過urllib2爬網頁上種子下載示例

    這篇文章主要介紹了通過urllib2、re模塊抓種子下載的示例,需要的朋友可以參考下
    2014-02-02
  • Pandas統(tǒng)計計數(shù)value_counts()的使用

    Pandas統(tǒng)計計數(shù)value_counts()的使用

    本文主要介紹了Pandas統(tǒng)計計數(shù)value_counts()的使用,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-07-07
  • python 基于opencv去除圖片陰影

    python 基于opencv去除圖片陰影

    這篇文章主要介紹了python 基于opencv去除圖片陰影的方法,幫助大家更好的理解和使用python,感興趣的朋友可以了解下
    2021-01-01
  • python實現(xiàn)雙鏈表

    python實現(xiàn)雙鏈表

    這篇文章主要為大家詳細介紹了python實現(xiàn)雙鏈表,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • Django使用uwsgi部署時的配置以及django日志文件的處理方法

    Django使用uwsgi部署時的配置以及django日志文件的處理方法

    今天小編就為大家分享一篇Django使用uwsgi部署時的配置以及django日志文件的處理方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-08-08
  • 用python爬取分析淘寶商品信息詳解技術篇

    用python爬取分析淘寶商品信息詳解技術篇

    這篇文章主要介紹了用python爬取分析淘寶商品信息的技術,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-08-08
  • Python 安裝 virturalenv 虛擬環(huán)境的教程詳解

    Python 安裝 virturalenv 虛擬環(huán)境的教程詳解

    這篇文章主要介紹了Python 安裝 virturalenv 虛擬環(huán)境的教程,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-02-02
  • python異常的捕捉和補救實例詳解

    python異常的捕捉和補救實例詳解

    在本篇文章里小編給大家整理的是一篇關于python異常的捕捉和補救實例詳解內容,有需要的朋友們可以跟著學習參考下。
    2021-06-06
  • Pygame游戲開發(fā)之太空射擊實戰(zhàn)盾牌篇

    Pygame游戲開發(fā)之太空射擊實戰(zhàn)盾牌篇

    相信大多數(shù)8090后都玩過太空射擊游戲,在過去游戲不多的年代太空射擊自然屬于經典好玩的一款了,今天我們來自己動手實現(xiàn)它,在編寫學習中回顧過往展望未來,在本課中,我們將為玩家添加一個盾牌以及一個用于顯示盾牌等級的欄
    2022-08-08

最新評論