這篇文章將為大家詳細講解有關Python如何利用Turtle庫繪制一個小老虎,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
哈嘍鐵汁們好久不見吖~小編已經復工了于是馬不停蹄趕來給大家準備新年禮物算開工禮物吧!

海龜來作圖
虎年就是要畫老虎
2022不用紙和筆~
今晚畫老虎~
一二三四五

老虎寶寶示意圖

虎年怎么能少得了老虎?畫只虎頭虎腦的可愛老虎,點燃除夕夜。不用紙和筆,就靠Python海龜作圖,小朋友趕緊代碼敲起來吧!
def laohu():
import turtle as t
# 設置幕布大小及顏色
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()# 左耳 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()
# 頭部輪廓 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)
# 兩虎眼
# 左眼
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) # 向左轉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) # 向左轉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)# 鼻子和嘴吧
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)# 小老虎肢體
# 左肢
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) # 向左轉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) # 向左轉3度
t.fd(a) # 向前走a的步長
else:
a = a - 0.03
t.lt(3)
t.fd(a)
t.end_fill()
# 每個腳趾繪制函數
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) # 向左轉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) # 向左轉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)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"))#顯示倒數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)# 顯示文字
def draw_1():
turtle.penup()
turtle.hideturtle() #隱藏箭頭顯示
turtle.goto(-410, 0)
turtle.color('red')
write = turtle.write('叮咚~新年禮物到啦????', font=('宋體', 60, 'normal'))
time.sleep(2)number=[3,2,1] #儲存顯示界面倒數數字1,2,3 if __name__ == '__main__': turtle.setup(900, 500) #調畫布的尺寸 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): # 需要的彈框數量 t = threading.Thread(target=dow) threads.append(t) time.sleep(0.01) threads[i].start()

關于“Python如何利用Turtle庫繪制一個小老虎”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。