# 皮卡丘 ``` #皮卡丘: 別人畫的 #python #https://www.cnblogs.com/ay2021/p/15023747.html import turtle def getPosition(x, y): turtle.setx(x) # 設置橫坐標為x turtle.sety(y) # 設置縱坐標為y print(x, y) class Pikachu: def __init__(self): self.t = turtle.Turtle() t = self.t t.pensize(3) t.speed(0) t.ondrag(getPosition) def noTrace_goto(self, x, y): self.t.penup() self.t.goto(x, y) self.t.pendown() def circle_color(self,color,radius,a,b,x,y): t = self.t self.noTrace_goto(x+a, y+b) t.fillcolor(color) t.begin_fill() t.circle(radius) t.end_fill() def Eye(self, x, y, a): self.t.seth(0) self.circle_color('#333333',22,0,0,x,y) # 深灰色 self.circle_color('black',10,0,10,x,y) self.circle_color('white',10,a,22,x,y) # a=左6,右-6 def mouth(self, x, y): self.noTrace_goto(x, y) t = self.t t.fillcolor('#88141D') t.begin_fill() # 下界是下嘴唇,上界是上嘴唇 #下嘴唇 l1,l2 = [],[] t.seth(190) # 左半 a = 0.7 for i in range(28): a += 0.1 t.right(3) t.fd(a) l1.append(t.position()) self.noTrace_goto(x, y) t.seth(10) # 右半 a = 0.7 for i in range(28): a += 0.1 t.left(3) t.fd(a) l2.append(t.position()) #上嘴唇 t.seth(10) # 右半右 t.circle(50, 15) # 10+15=25 t.left(180) # 25+180=205 t.circle(-50, 55) # 右半: 205-55=150 t.seth(233) # 左半 t.circle(-50, 55) t.left(180) t.circle(50, 12.1) t.end_fill() #舌頭 self.noTrace_goto(17, 54) t.fillcolor('#DD716F') t.begin_fill() t.seth(145) # 舌右端 t.circle(40, 86) for pos in reversed(l1[:20]): t.goto(pos[0], pos[1]+1.5) # 舌下左 for pos in l2[:20]: t.goto(pos[0], pos[1]+1.5) # 舌下右 t.end_fill() #鼻子 self.noTrace_goto(-21, 93.5) t.seth(8) # 8 t.fd(8) # 8 #紅臉頰 def Cheek(self, x, y, angle): self.noTrace_goto(x, y) t = self.t t.seth(angle) # 左300, 右60 t.fillcolor('#DD4D28') t.begin_fill() a = 2.3 for i in range(120): if 0 <= i < 30 or 60 <= i < 90: a -= 0.05 t.lt(3) t.fd(a) else: a += 0.05 t.lt(3) t.fd(a) t.end_fill() def colorLeftEar(self, x, y): t = self.t self.noTrace_goto(x, y) t.fillcolor('black') t.begin_fill() t.seth(330) # 上 t.circle(100, 35) t.seth(219) # 右 t.circle(-300, 19) t.seth(110) # 左 t.circle(-30, 50) t.circle(-300, 10) # 左上 t.end_fill() def colorRightEar(self, x, y): t = self.t self.noTrace_goto(x, y) t.fillcolor('black') t.begin_fill() t.seth(300) # 左 t.circle(-100, 30) t.seth(35) # 下 t.circle(300, 15) t.circle(30, 50) # 右 t.seth(190) # 上 t.circle(300, 17) t.end_fill() def tail(self,a): t = self.t t.seth(-45) # 右3 t.fd(a) # 67 t.right(110) # 下3 t.fd(80) t.left(110) # 右4 t.fd(30) t.right(110) # 下4 t.fd(32) t.right(106) # 尾左下 t.circle(100, 25) t.right(15) t.circle(-300, 2) def body(self): t = self.t t.fillcolor('#F6D02F') t.begin_fill() #右臉輪廓 t.penup() t.circle(130, 40) t.pendown() t.circle(100, 105) t.left(180) t.circle(-100, 5) #右耳朵 t.seth(20) # 下 t.circle(300, 30) t.circle(30, 50) # 右 t.seth(190) # 上 t.circle(300, 36) #上輪廓 t.seth(150) t.circle(150, 70) #左耳朵 t.seth(200) # 上 t.circle(300, 40) t.circle(30, 50) # 左 t.seth(20) # 下 t.circle(300, 35) # print(t.pos()) #左臉輪廓 t.seth(240) t.circle(105, 95) t.left(180) t.circle(-105, 5) #左手 t.seth(210) # 上邊 t.circle(500, 18) t.seth(200) # 第1指 t.fd(10) t.seth(280) t.fd(7) t.seth(210) # 第2指 t.fd(10) t.seth(300) t.circle(10, 80) t.seth(220) # 第3指 t.fd(10) t.seth(300) t.circle(10, 80) t.seth(240) # 第4指 t.fd(12) t.seth(0) t.fd(13) t.seth(240) # 第5指 t.circle(10, 70) t.seth(10) t.circle(10, 70) t.seth(10) # 下邊 t.circle(300, 18) t.seth(75) # 左身上 t.circle(500,8) t.left(180) t.circle(-500, 15) t.seth(250) # 左身下 t.circle(100, 65) #左腳 t.seth(320) # 左上紋 t.circle(100, 5) t.left(180) t.circle(-100, 5) t.seth(220) # 上邊 t.circle(200, 20) t.circle(20, 70) # 第1趾趾頭 t.seth(60) # 第1趾 t.circle(-100, 20) t.left(180) t.circle(100, 20) t.seth(300) # 第2趾趾頭 t.circle(10, 70) t.seth(60) # 第2趾 t.circle(-100, 20) t.left(180) t.circle(100, 20) t.seth(10) # 下邊 t.circle(100, 60) #横向 t.seth(180) # 左腳右上紋 t.circle(-100, 10) t.left(180) t.circle(100, 10) t.seth(5) # 身體下邊 t.circle(100, 10) t.circle(-100, 40) t.circle(100, 35) t.left(180) # 右腳左上紋 t.circle(-100, 10) #右腳 t.seth(290) # 下邊 t.circle(100, 55) t.circle(10, 50) # 第1趾趾頭 t.seth(120) # 第1趾 t.circle(100, 20) t.left(180) t.circle(-100, 20) t.seth(0) # 第2趾趾頭 t.circle(10, 50) t.seth(110) # 第2趾 t.circle(100, 20) t.left(180) t.circle(-100, 20) t.seth(30) # 第3趾趾頭 t.circle(20, 50) t.seth(100) # 上邊 t.circle(100, 40) #右側身體輪廓 t.seth(200) # 右腳右上紋 t.circle(-100, 5) t.left(180) t.circle(100, 5) t.left(30) # 右下 # 200-180+30=50度 t.circle(100, 75) # 50+75=125 t.right(15) # 右 # 125-15=110* t.circle(-300, 21) # 110-21=89 t.left(180) t.circle(300, 3) #右手 t.seth(43) # 下 t.circle(200, 60) # 43+60=103 t.right(10) # 第5指上半: 43+60-10=93度 t.fd(10) t.circle(5, 160) t.seth(90) # 第4指上半 t.circle(5, 160) t.seth(90) # 第3指 t.fd(10) t.circle(5, 180) t.fd(10) t.seth(110) # 第2指 t.fd(10) t.circle(5, 170) t.fd(10) t.seth(240) # 第1指邊 t.circle(50, 30) t.end_fill() self.noTrace_goto(130, 125) t.seth(-20) # 第1指 t.fd(5) t.circle(-5, 160) t.fd(5) #手指紋 self.noTrace_goto(166, 130) t.seth(-90) # 第4指下半 t.fd(3) t.circle(-4, 180) t.fd(3) t.seth(-90) # 第5指下半 t.fd(3) t.circle(-4, 180) t.fd(3) #尾巴 self.noTrace_goto(168, 134) t.fillcolor('#F6D02F') t.begin_fill() t.seth(40) # 上邊 t.fd(200) t.seth(-80) # 右1 t.fd(150) t.seth(210) # 下1 t.fd(150) t.left(90) # 右2 t.fd(100) t.right(95) # 下2 t.fd(100) self.tail(70) ############## t.seth(30) # 上1 t.fd(40) t.left(100) # 左1 t.fd(70) t.right(100) # 上2 t.fd(80) t.left(100) # 左2 t.fd(46) t.seth(66) # 尾左上 t.circle(200, 38) # 66+38=104 t.right(10) # 104-10=94 t.fd(10) t.end_fill() #尾巴花紋 t.fillcolor('#923E24') self.noTrace_goto(127, -157) t.begin_fill() t.seth(30) # 上1 t.fd(40) t.left(100) # 左1 t.fd(40) t.pencolor('#923e24') t.seth(-30) # 紋右1 t.fd(30) t.left(140) # 紋左1 t.fd(20) t.right(150) # 紋右2 t.fd(20) t.left(150) # 紋左2 t.fd(20) t.right(150) # 紋右3 t.fd(20) t.left(130) # 紋左3 t.fd(18) t.pencolor('black') self.tail(67) t.end_fill() #帽子、眼睛、嘴巴、臉頰 self.cap(-134, 148) self.mouth(-5, 25) self.Cheek(-126, 32, 300) # 左 self.Cheek(107, 63, 60) # 右 self.colorLeftEar(-250, 100) self.colorRightEar(140, 270) self.Eye(-85, 90, 6) # 左 self.Eye(50, 110, -6) # 右 t.hideturtle() def cap(self, x, y): self.noTrace_goto(x, y) t = self.t t.fillcolor('#CD0000') t.begin_fill() t.seth(200) # 下 t.circle(400, 7) t.left(180) t.circle(-400, 30) t.circle(30, 60) # 右下角 t.fd(50) # 右下 t.circle(30, 45) t.fd(60) # 右上 t.left(5) t.circle(30, 70) t.right(20) # 上 t.circle(200, 70) t.circle(30, 60) # 左上角 t.fd(70) # 左上 t.right(35) # 左下 t.fd(50) t.circle(8, 80) # 左下角 t.end_fill() self.noTrace_goto(-169, 186) t.seth(36) # 帽板上 t.circle(-270, 54) self.noTrace_goto(-145, 312) t.fillcolor('#444444') t.begin_fill() t.seth(271) # 帽身圓下 t.circle(80, 197) t.left(58) # 帽身圓上 t.circle(200, 45) t.end_fill() self.noTrace_goto(-58, 270) t.pencolor('#228B22') t.dot(35) # 畫直徑35的圓 self.noTrace_goto(-30, 280) t.fillcolor('#228B22') t.begin_fill() t.seth(100) # U下 t.circle(30, 180) t.seth(190) # U下左 t.fd(15) t.seth(100) # U上 t.circle(-45, 180) t.right(90) # U下右 t.fd(15) t.end_fill() t.pencolor('black') #def start(self): self.body() def main(): print('Painting the Pikachu... ') turtle.screensize(800, 600) turtle.title('Pikachu') Pikachu().body() turtle.mainloop() # 作為繪圖的結束語句 #<class 'function'> if __name__ == '__main__': #print(type(turtle.Screen().mainloop)) # <class 'method'> main() ``` ![](https://i.imgur.com/7GuypkP.jpg)