Python學習筆記--畫個可愛的叮噹喵
阿新 • • 發佈:2018-11-04
參考大神的連結:你看過/寫過哪些有意思的程式碼? - 暴走的bug的回答 - 知乎
https://www.zhihu.com/question/275611095/answer/382959285
前一段時間在知乎看到了一個大神的作品,他用turtl庫畫了一個小豬佩奇!剛看到我就驚呆了,看了一下程式碼,咦,好簡單哎,這麼簡單的程式碼可以寫出這麼好玩的東西呀~於是心裡就一直也想畫一個,想畫個可愛的叮噹喵~
不過還在整修中……因為感覺怎麼……額…沒有我想的那麼萌???而且大神已更新到小豬佩奇2.0我還沒更新~
# coding:utf-8
import turtle as t
import time
t.pensize(4)
t.pencolor('black')
t.hideturtle()
t.setup(800,600)
t.speed(0)
# 外臉輪廓
t.penup()
t.goto(200,50)
t.color('black','blue')
t.pendown()
t.seth(30)
t.circle(100,300)#半徑、角度
# 眼睛
# 左眼睛
t.penup()
t.goto(120,210)
t.pendown()
t.seth(180)
a=0.4
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的步長
else:
a=a-0.05
t.lt(3)
t.fd(a)
#左眼珠
t.pu()
t.seth(-70)
t.fd(17)
t.seth(180)
t.pd()
t.begin_fill()
a=0.15
for i in range(120):
if 0<=i<30 or 60<=i<90:
a=a+0.02
t.lt(3) #向左轉3度
t.fd(a) #向前走a的步長
else :
a=a-0.02
t.lt(3)
t.fd(a)
t.color('black')
t.end_fill()
#左眼神
t.pu()
t.seth(-90)
t.fd(5)
t.pd()
t.color('white')
t.begin_fill()
t.circle(2)
t.end_fill()
# 右眼睛
t.pu()
t.goto(180,210)
t.pencolor('black')
t.pd()
t.seth(180)
a=0.4
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的步長
else:
a=a-0.05
t.lt(3)
t.fd(a)
#右眼珠
t.pu()
t.seth(-110)
t.fd(17)
t.seth(180)
t.pd()
t.begin_fill()
a=0.15
for i in range(120):
if 0<=i<30 or 60<=i<90:
a=a+0.02
t.lt(3) #向左轉3度
t.fd(a) #向前走a的步長
else:
a=a-0.02
t.lt(3)
t.fd(a)
t.color('black')
t.end_fill()
#右眼神
t.pu()
t.seth(-90)
t.fd(5)
t.pd()
t.color('white')
t.begin_fill()
t.circle(2)
t.end_fill()
# 鼻子
t.pu()
t.color('black','red') # 畫筆顏色,填充顏色
t.goto(150,160)
t.seth(180)
t.pd()
t.begin_fill()
t.circle(10)
t.end_fill()
t.pu()
t.seth(-90)
t.fd(5)
t.pd()
t.color('white')
t.begin_fill()
t.circle(2)
t.end_fill()
# 嘴巴
t.pu()
t.pencolor('black')
t.seth(-90)
t.fd(12)
t.pd()
t.fd(70)
t.pu()
t.seth(90)
t.fd(17)
t.seth(0)
t.fd(-60)
t.pd()
t.seth(-50)
t.circle(80,100)
# 舌頭
t.pu()
t.seth(120)
t.fd(5)
t.pd()
t.seth(-60)
t.fd(10)
t.pu()
t.seth(180)
t.fd(52)
t.seth(-60)
t.fd(20)
t.pd()
t.color('black','red')
t.begin_fill()
t.seth(120)
t.circle(-40,50)
t.circle(-10,80)
t.circle(-40,50)
t.end_fill()
t.pu()
t.seth(180)
t.fd(20)
t.pd()
t.seth(-60)
t.fd(12)
# 內臉輪廓
t.pu()
t.goto(100,50)
t.color('black')
t.seth(130)
t.pd()
t.circle(-110,40)
t.circle(-70,40)
t.circle(-100,10)
t.pu()
t.goto(200,50)
t.seth(50)
t.pd()
t.circle(110,40)
t.circle(70,40)
t.circle(100,10)
#鬍子
# 右邊的鬍子
t.pu()
t.goto(200,150)
t.seth(30)
t.pd()
t.fd(30)
t.pu()
t.seth(180)
t.fd(23)
t.seth(-90)
t.fd(25)
t.pd()
t.seth(10)
t.fd(30)
t.pu()
t.seth(180)
t.fd(28)
t.seth(-90)
t.fd(20)
t.pd()
t.seth(-10)
t.fd(30)
# 左邊的鬍子
t.pu()
t.goto(100,150)
t.seth(150)
t.pd()
t.fd(30)
t.pu()
t.seth(0)
t.fd(23)
t.seth(-90)
t.fd(25)
t.pd()
t.seth(170)
t.fd(30)
t.pu()
t.seth(0)
t.fd(28)
t.seth(-90)
t.fd(20)
t.pd()
t.seth(-170)
t.fd(30)
t.done()
time.sleep(1)
我的小叮噹~~
不過真的還蠻開心的~~
程式設計很有趣嘛~