欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python利用Turtle庫繪制一個小老虎

 更新時間:2022年02月26日 15:40:54   作者:車?yán)遄覢  
虎年就是要畫老虎!本文將通過Python中的Turtle庫繪制一個可愛的小老虎,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下

導(dǎo)語

哈嘍鐵汁們好久不見吖~小編已經(jīng)復(fù)工了于是馬不停蹄趕來給大家準(zhǔn)備新年禮物算開工禮物吧!

海龜來作圖

虎年就是要畫老虎

2022不用紙和筆~

今晚畫老虎~

一二三四五

老虎寶寶示意圖

虎年怎么能少得了老虎?畫只虎頭虎腦的可愛老虎,點燃除夕夜。不用紙和筆,就靠Python海龜作圖,小朋友趕緊代碼敲起來吧!

1.定義庫以及初始化界面

def laohu():
    import turtle as t
    # 設(shè)置幕布大小及顏色
    t.screensize(50, 50, bg='yellow')
    t.title("老虎寶寶")
    t.shape("classic")
    t.pensize(10)
    t.color("orange")
    t.fillcolor("pink")
    t.speed(100)
    t.hideturtle()

2.畫出左右兩只耳朵

# 左耳
    t.penup()
    t.goto(-105, 97)
    t.setheading(160)
    t.begin_fill()
    t.pendown()
    t.circle(-30, 230)
    t.setheading(180)
    t.circle(37, 90)
    t.end_fill()
    # 右耳
    t.penup()
    t.goto(105, 97)
    t.setheading(20)
    t.begin_fill()
    t.pendown()
    t.circle(30, 230)
    t.setheading(0)
    t.circle(-37, 90)
    t.end_fill()

3.畫出小老虎頭部輪廓

# 頭部輪廓
    t.penup()
    t.goto(-67, 140)
    t.setheading(30)
    t.pendown()
    t.circle(-134, 60)
 
    t.penup()
    t.goto(-50, -25)
    t.setheading(180)
    t.pendown()
    t.circle(-100, 30)
    t.circle(-30, 90)
    t.setheading(100)
    t.circle(-200, 20)
 
    t.penup()
    t.goto(50, -25)
    t.setheading(0)
    t.pendown()
    t.circle(100, 30)
    t.circle(30, 90)
    t.setheading(80)
    t.circle(200, 20)

4. 畫出老虎的兩只眼睛

# 兩虎眼
    # 左眼
    t.penup()
    t.goto(-90, 25)
    t.setheading(-45)
    t.fillcolor("orange")
    t.begin_fill()
    t.pendown()
    # 橢圓繪制技巧
    a = 0.2
    for i in range(120):
        if 0 <= i < 30 or 60 <= i < 90:
            a = a + 0.1
            t.lt(3)  # 向左轉(zhuǎn)3度
            t.fd(a)  # 向前走a的步長
        else:
            a = a - 0.1
            t.lt(3)
            t.fd(a)
    t.end_fill()
 
    t.fillcolor("pink")
    t.penup()
    t.goto(-53, 43)
    t.setheading(0)
    t.begin_fill()
    t.pendown()
    t.circle(19, 360)
    t.end_fill()
 
    t.penup()
    t.pensize(4)
    t.goto(-60, 57)
    t.setheading(30)
    t.pendown()
    t.circle(-12, 60)
    # 右眼
    t.penup()
    t.goto(90, 25)
    t.setheading(45)
    t.pensize(2)
    t.fillcolor("orange")
    t.begin_fill()
    t.pendown()
    # 橢圓繪制技巧
    a = 0.2
    for i in range(120):
        if 0 <= i < 30 or 60 <= i < 90:
            a = a + 0.1
            t.lt(3)  # 向左轉(zhuǎn)3度
            t.fd(a)  # 向前走a的步長
        else:
            a = a - 0.1
            t.lt(3)
            t.fd(a)
    t.end_fill()
 
    t.fillcolor("pink")
    t.penup()
    t.goto(53, 43)
    t.setheading(0)
    t.begin_fill()
    t.pendown()
    t.circle(13, 360)
    t.end_fill()
 
    t.penup()
    t.pensize(4)
    t.goto(60, 57)
    t.setheading(150)
    t.pendown()
    t.circle(12, 60)

5.畫出老虎的鼻子和嘴巴

# 鼻子和嘴吧
    t.penup()
    t.goto(-16, 20)
    t.setheading(-90)
    t.fillcolor("pink")
    t.begin_fill()
    t.pendown()
    a = 0.2
    for i in range(120):
        if 0 <= i < 30 or 60 <= i < 90:
            a = a + 0.03
            t.lt(3)
            t.fd(a)
        else:
            a = a - 0.03
            t.lt(3)
            t.fd(a)
    t.end_fill()
 
    t.penup()
    t.goto(-24, 0)
    t.setheading(-60)
    t.pendown()
    t.circle(28, 120)

6.畫出小老虎的左右肢體和腳趾

# 小老虎肢體
    # 左肢
    t.color("orange")
    t.penup()
    t.goto(-65, -24)
    t.setheading(-140)
    t.begin_fill()
    t.pendown()
    t.circle(100, 40)
    t.setheading(180)
    t.circle(30, 40)
    t.setheading(-40)
    t.circle(40, 40)
    t.setheading(-150)
    a = 0.5
    for i in range(120):
        if 0 <= i < 30 or 60 <= i < 90:
            a = a + 0.05
            t.lt(3)  # 向左轉(zhuǎn)3度
            t.fd(a)  # 向前走a的步長
        elif 30 <= i < 60 or 90 <= i < 100:
            a = a - 0.05
            t.lt(3)
            t.fd(a)
    t.setheading(93)
    t.circle(-150, 30)
    t.end_fill()
 
    t.penup()
    t.goto(-85, -115)
    t.setheading(-150)
    t.color("pink", "pink")
    t.begin_fill()
    t.pendown()
    a = 0.3
    for i in range(120):
        if 0 <= i < 30 or 60 <= i < 90:
            a = a + 0.03
            t.lt(3)  # 向左轉(zhuǎn)3度
            t.fd(a)  # 向前走a的步長
        else:
            a = a - 0.03
            t.lt(3)
            t.fd(a)
    t.end_fill()
 
    # 每個腳趾繪制函數(shù)
 
    def toe(x, y):
        t.begin_fill()
        t.goto(x, y)
        t.circle(3, 360)
        t.end_fill()
 
    t.penup()
    toe(-98, -120)
    toe(-96, -110)
    toe(-88, -105)
    toe(-80, -105)
 
    # 右肢
    t.color("orange")
    t.penup()
    t.goto(65, -24)
    t.setheading(-40)
    t.begin_fill()
    t.pendown()
    t.circle(-100, 40)
    t.setheading(0)
    t.circle(-30, 40)
    t.setheading(-140)
    t.circle(-40, 40)
    t.setheading(-30)
    a = 0.5
    for i in range(120):
        if 0 <= i < 30 or 60 <= i < 90:
            a = a + 0.05
            t.rt(3)  # 向左轉(zhuǎn)3度
            t.fd(a)  # 向前走a的步長
        elif 30 <= i < 60 or 90 <= i < 100:
            a = a - 0.05
            t.rt(3)
            t.fd(a)
    t.setheading(87)
    t.circle(150, 30)
    t.end_fill()
 
    t.penup()
    t.goto(85, -115)
    t.setheading(150)
    t.color("pink", "pink")
    t.begin_fill()
    t.pendown()
    a = 0.3
    for i in range(120):
        if 0 <= i < 30 or 60 <= i < 90:
            a = a + 0.03
            t.lt(3)  # 向左轉(zhuǎn)3度
            t.fd(a)  # 向前走a的步長
        else:
            a = a - 0.03
            t.lt(3)
            t.fd(a)
    t.end_fill()
 
    t.penup()
    toe(98, -120)
    toe(96, -110)
    toe(88, -105)
    toe(80, -105)

7.在需要的位置寫上我們的新年祝福

t.goto(-57, -140)
    t.color("orange")
    t.setheading(-20)
    t.pendown()
    t.circle(165, 40)
    t.penup()
    t.goto(0, 180)
    t.write("祝大家虎年快樂,虎虎生威!",
            align="center", font=("Times", 28, "bold"))
 
    t.color("black")
    t.penup()
    t.goto(0, 80)
    t.write("王",
            align="center", font=("Times", 38, "bold"))
    t.penup()
    t.goto(0, -5)
    t.write("一                   一",
            align="center", font=("Times", 18, "bold"))
    t.goto(0, -15)
    t.write("一                   一",
            align="center", font=("Times", 18, "bold"))
    t.goto(0, -25)
    t.write("一                   一",
            align="center", font=("Times", 18, "bold"))

8. 顯示倒數(shù)3,2,1

#顯示倒數(shù)3,2,1
def draw_0(i):
    turtle.screensize(50, 50, bg='yellow')
    turtle.speed(0)
    turtle.penup()
    turtle.hideturtle()  # 隱藏箭頭顯示
    turtle.goto(-50, -100)
    turtle.color('red')
    write = turtle.write(i, font=('宋體', 200, 'normal'))
    time.sleep(1)

9.顯示我們需要的文字

# 顯示文字
def draw_1():
    turtle.penup()
    turtle.hideturtle()    #隱藏箭頭顯示
    turtle.goto(-410, 0)
    turtle.color('red')
    write = turtle.write('叮咚~新年禮物到啦??', font=('宋體', 60, 'normal'))
    time.sleep(2)

10.設(shè)定代碼運行入口,調(diào)用目標(biāo)函數(shù)

number=[3,2,1]    #儲存顯示界面倒數(shù)數(shù)字1,2,3
if __name__ == '__main__':
    turtle.setup(900, 500)     #調(diào)畫布的尺寸
    for i in number:
        turtle.screensize(50, 50, bg='yellow')
        draw_0(i)
        clear_screen()
    turtle.screensize(50, 50, bg='yellow')
    draw_1()
    clear_screen()
    turtle.screensize(50, 50, bg='yellow')
    laohu()
    time.sleep(5)
    threads = []
    for i in range(100):  # 需要的彈框數(shù)量
        t = threading.Thread(target=dow)
        threads.append(t)
        time.sleep(0.01)
        threads[i].start()

成果展示

用Python畫的小老虎

以上就是Python利用Turtle庫繪制一個小老虎的詳細(xì)內(nèi)容,更多關(guān)于Python Turtle繪制老虎的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Python利用Pandas進(jìn)行數(shù)據(jù)分析的方法詳解

    Python利用Pandas進(jìn)行數(shù)據(jù)分析的方法詳解

    Pandas是最流行的用于數(shù)據(jù)分析的?Python?庫。它提供高度優(yōu)化的性能。本文將利用Python進(jìn)行數(shù)據(jù)分析,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2022-09-09
  • Python使用chardet判斷字符編碼

    Python使用chardet判斷字符編碼

    這篇文章主要介紹了Python使用chardet判斷字符編碼的方法,較為詳細(xì)的分析了Python中chardet的功能、安裝及使用技巧,需要的朋友可以參考下
    2015-05-05
  • Python中plt.scatter()函數(shù)的常見用法小結(jié)

    Python中plt.scatter()函數(shù)的常見用法小結(jié)

    這篇文章主要介紹了Python中plt.scatter()函數(shù)的常見用法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-04-04
  • opencv實現(xiàn)圖像平移效果

    opencv實現(xiàn)圖像平移效果

    這篇文章主要為大家詳細(xì)介紹了opencv實現(xiàn)圖像平移效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-03-03
  • Pandas替換NaN值的方法實現(xiàn)

    Pandas替換NaN值的方法實現(xiàn)

    本文主要介紹了Pandas替換NaN值的方法實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-01-01
  • Python3 加密(hashlib和hmac)模塊的實現(xiàn)

    Python3 加密(hashlib和hmac)模塊的實現(xiàn)

    本篇文章主要介紹了Python3 加密(hashlib / hmac)模塊的實現(xiàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-11-11
  • 詳解Python中的文本處理

    詳解Python中的文本處理

    這篇文章主要介紹了Python中的文本處理,包括從最基本的string模塊的基礎(chǔ)使用和更進(jìn)一步的re模塊的使用,本文來自IBM官方開發(fā)者技術(shù)文檔,需要的朋友可以參考下
    2015-04-04
  • linux 下python多線程遞歸復(fù)制文件夾及文件夾中的文件

    linux 下python多線程遞歸復(fù)制文件夾及文件夾中的文件

    這篇文章主要介紹了linux 下python多線程遞歸復(fù)制文件夾及文件夾中的文件,本文通過實例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-01-01
  • 解讀dataframe中有關(guān)inf的處理技巧

    解讀dataframe中有關(guān)inf的處理技巧

    這篇文章主要介紹了解讀dataframe中有關(guān)inf的處理技巧,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • Python入門教程(十一)Python中的運算符

    Python入門教程(十一)Python中的運算符

    這篇文章主要介紹了Python入門教程(十一)Python中的運算符,Python是一門非常強(qiáng)大好用的語言,也有著易上手的特性,本文為入門教程,需要的朋友可以參考下
    2023-04-04

最新評論