Python利用Turtle繪制哆啦A夢和小豬佩奇
1.哆啦A夢
“只要把愿望系在竹竿上請求月亮女神,心愿便能達(dá)成”。我超喜歡這句話。
哆啦A夢的創(chuàng)造要追溯到1969年的某個(gè)截稿日,作者藤子·F·不二雄的家里突然闖進(jìn)了一只小貓,雖然很快就要截稿了,但作者還是和小貓玩了起來,還替小貓撓虱子,而這一撓就是幾個(gè)小時(shí)。等作者發(fā)現(xiàn)時(shí)間不夠用的時(shí)候,已經(jīng)來不及完成稿子。這時(shí)作者像熱鍋上的螞蟻?zhàn)邅碜呷?,突然踢到了女兒的不倒翁玩具,于是作者靈光一現(xiàn),把貓的形象和不倒翁結(jié)合起來,就創(chuàng)造了哆啦A夢。
2.小豬佩奇
對比于國內(nèi)的《喜羊羊與灰太狼》和《熊出沒》,我希望有一天喜羊羊被灰太狼燉了、熊大被光頭強(qiáng)一槍打中,然后直接賣到動(dòng)物園。(哈哈哈......)可是這個(gè)想法一直沒實(shí)現(xiàn),有些失落。還是看小豬佩奇吧:
由英國E1 Kids于2004年5月31日發(fā)行首播后,其動(dòng)畫片已于全球180個(gè)地區(qū)播放,現(xiàn)已播出6季;
中國中央電視臺少兒頻道也在熱播之中,極簡的動(dòng)畫風(fēng)格,幽默的對話語調(diào),深具教育意義的故事情節(jié),不僅能讓學(xué)齡前兒童學(xué)習(xí)知識,更能讓小朋友們從小養(yǎng)成良好的生活習(xí)慣體驗(yàn)生活,深受全球各地小朋友們以及其家長們的喜愛。
3.Python代碼實(shí)現(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) # 向左轉(zhuǎn)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) # 向左轉(zhuǎn)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()
# 領(lǐng)帶
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代碼實(shí)現(xiàn)(小豬佩奇 )

import turtle
from turtle import *
turtle.title('小豬佩奇')
def nose(x,y):
"""畫鼻子"""
pensize(5)
pencolor((255, 155, 192))
penup()
# 將海龜移動(dòng)到指定的坐標(biāo)
goto(x,y)
pendown()
# 設(shè)置海龜?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
# 向左轉(zhuǎn)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()
"""設(shè)置畫筆的顏色(紅, 綠, 藍(lán))"""
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) #向左轉(zhuǎn)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
# 向左轉(zhuǎn)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
# 向左轉(zhuǎn)3度
left(3)
# 向前走
forward(a)
else:
a = a - 0.13
left(3)
forward(a)
end_fill()
def setting():
"""設(shè)置參數(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夢和小豬佩奇的詳細(xì)內(nèi)容,更多關(guān)于Python哆啦A夢 小豬佩奇的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
通過5個(gè)例子讓你學(xué)會Pandas中的字符串過濾
毋庸置疑Pandas是使用最廣泛的Python庫之一,它提供了許多功能和方法來執(zhí)行有效的數(shù)據(jù)處理和數(shù)據(jù)分析,下面這篇文章主要給大家介紹了關(guān)于如何通過5個(gè)例子讓你學(xué)會Pandas中字符串過濾的相關(guān)資料,需要的朋友可以參考下2022-08-08
Python?Pygame實(shí)戰(zhàn)之打磚塊游戲的實(shí)現(xiàn)
這篇文章主要介紹了如何利用Python實(shí)現(xiàn)經(jīng)典的游戲—打磚塊。玩家操作一根螢?zāi)簧纤降摹鞍糇印?,讓一顆不斷彈來彈去的“球”在撞擊作為過關(guān)目標(biāo)消去的“磚塊”的途中不會落到螢?zāi)坏紫?。感興趣的小伙伴可以了解一下2022-03-03
python動(dòng)態(tài)加載技術(shù)解析
這篇文章主要介紹了python動(dòng)態(tài)加載技術(shù)解析,說簡單點(diǎn)就是,如果開發(fā)者發(fā)現(xiàn)自己的代碼有bug,那么他可以在不關(guān)閉原來代碼的基礎(chǔ)之上,動(dòng)態(tài)替換模塊替換方法一般用reload來完成,需要的朋友可以參考下2023-07-07

