用 Python 畫哆啦 A 夢

導讀:相信大家童年的時候都看過哆啦 A 夢,他的口袋簡直是無所不能,里面裝滿了各種神奇的道具。曾經的我也幻想過如果自己也有一個這樣的口袋多好。今天我們就用 Python 來畫一個哆啦 A 夢,懷念下我們的童年。

01 頭部輪廓和圍巾
import?turtle?as?t
t.speed(5)
t.pensize(1)
t.screensize(500,?500)
t.bgcolor('white')#?頭部
def?head():
????t.up()
????t.circle(150,?45)
????t.down()
????t.fillcolor(head_color)
????t.begin_fill()
????t.circle(150,?270)
????t.end_fill()
#?圍巾
def?scarf():
????t.fillcolor(scarf_color)
????t.begin_fill()
????t.seth(0)
????t.fd(216)
????t.circle(-5,?90)
????t.fd(10)
????t.circle(-5,?90)
????t.fd(220)
????t.circle(-5,?90)
????t.fd(10)
????t.circle(-5,?90)
????t.end_fill()
02 臉部
1. 眼睛
def?face():
????t.fd(186)
????t.lt(45)
????t.fillcolor(color_white)
????t.begin_fill()
????t.circle(120,?100)
????t.seth(180)
????t.fd(120)
????t.seth(215)
????t.circle(120,?100)
????t.end_fill()
def?draw_eyes():
????t.fillcolor(color_white)
????t.begin_fill()
????a?=?2.5
????for?i?in?range(120):
????????if?0?<=?i?30?or?60?<=?i?90:
????????????a?-=?0.05
????????else:
????????????a?+=?0.05
????????t.lt(3)
????????t.fd(a)
????t.end_fill()
def?eyes():
????go_to(0,?227)
????t.seth(90)
????draw_eyes()
????go_to(0,?227)
????t.seth(270)
????draw_eyes()
def?fill_eyes():
????#?填充眼睛
????go_to(-15,?220)
????t.pensize(12)
????t.color('black')
????for?i?in?range(30):
????????t.forward(2)
????????t.right(12)
????go_to(15,?220)
????for?i?in?range(30):
????????t.forward(2)
????????t.left(12)
????t.pensize(1)
2. 鼻子 & 嘴巴
#?鼻子
def?nose():
????go_to(-13,?166)
????t.seth(315)
????t.fillcolor(nose_color)
????t.begin_fill()
????t.circle(20)
????t.end_fill()
#?嘴巴
def?mouth():
????go_to(0,?156)
????t.seth(270)
????t.fd(100)
????pos?=?t.pos()
????t.seth(0)
????t.circle(110,?60)
????go_to(pos[0],?pos[1])
????t.seth(180)
????t.circle(-110,?60)
3. 胡須 & 鈴鐺
#?胡須
def?mustache():
????h?=?70
????go_to(30,?140)
????t.seth(15)
????t.fd(h)
????go_to(30,?130)
????t.seth(0)
????t.fd(h)
????go_to(30,?120)
????t.seth(-15)
????t.fd(h)
????go_to(-30,?140)
????t.seth(150)
????t.fd(h)
????go_to(-30,?130)
????t.seth(180)
????t.fd(h)
????go_to(-30,?120)
????t.seth(195)
????t.fd(h)
#?鈴鐺
def?bell():
????#?大圓
????go_to(0,?33)
????t.pensize(1)
????t.fillcolor("#FCE341")
????t.begin_fill()
????t.circle(25)
????t.end_fill()
????#?橫條紋
????go_to(-15,?22)
????t.seth(0)
????t.forward(42)
????go_to(-18,?17)
????t.seth(0)
????t.forward(47)
????#?小圓
????go_to(5,?0)
????t.pensize(1)
????t.color("black",?'#79675D')
????t.begin_fill()
????t.circle(5)
????t.end_fill()
????t.seth(270)
????t.pensize(1)
????t.forward(15)if?__name__?==?'__main__':
????head()
????scarf()
????face()
????eyes()
????fill_eyes()
????nose()
????mouth()
????mustache()
????bell()
????go_to()
????t.hideturtle()
????t.done()

03 總結


干貨直達??

評論
圖片
表情
