Código de programación Python Pikachu
importar tortuga
def getPosition(x, y):
tortuga.setx(x)
tortuga.sety(y)
print(x, y)
clase Pikachu:
def __init__(self):
self.t = tortuga.Tortuga ()
t = self.t
t.pensize(3)
t.speed(9)
t.ondrag (getPosition)
def noTrace_goto(self, x, y):
self.t.penup()
self.t.goto(x, y )
self.t.pendown()
def leftEye(self, x, y):
self.noTrace_goto(x, y)
t = self.t
t.seth(0)
t.fillcolor('#333333')
t.begin_fill()
t.circle(22)
t.end_fill()
self.noTrace_goto(x, y 10)
t. fillcolor('#000000')
t.begin_fill()
t.circle(10)
t.end_fill()
self.noTrace_goto(x 6, y 22)
t.fillcolor('#ffffff')
t.begin_fill()
t.circle( 10)
t.end_fill()
def rightEye(self, x, y):
self.noTrace_goto(x, y)
t = self.t
t.seth(0)
t.fillcolor('#333333')
t.begin_fill()
t.circle(22)
t.end_fill()
self.noTrace_goto(x, y 10)
t.fillcolor ('#000000')
t.begin_fill()<
/p>
t.circle(10)
t.end_fill()
self.noTrace_goto(x-6, y 22)
t .fillcolor('#ffffff')
t.begin_fill()
t.circle(10)
t.end_fill()
def boca(self, x, y):
self.noTrace_goto(x, y)
t = self.t
t.fillcolor( '#88141D')
t.begin_fill()
# Labio inferior
l1 = []
l2 = []
t.seth(190)
a = 0,7
para i en el rango(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
para i en el rango(28):
a = 0.1
t.left(3)
t.fd(a)
l2.append(t.position())
# Labio superior
t.seth(10)
t.circle(50, 15)
t.left(180)
t.circle(-50, 15)
t.circle(-50, 40)
t.seth(233)
t .circle(-50, 55)
t.left(180)
t.circle(50, 12.1)
t.end_fill() p> p>
# Lengua
self.noTrace_goto(17, 54)
t.fillcolor('#DD716F')
t.begin_fill ()
t.seth(145)
t.circle(40, 86)
t
.penup()
para pos en invertido(l1[:20]):
t.goto(pos[0], pos[1] 1.5)
para pos en l2[:20]:
t.goto(pos[0], pos[1] 1.5)
t.pendown()
t.end_fill()
# nariz
self.noTrace_goto(-17, 94)
t.seth(8)
t.fd(4)
t.back(8)
# Mejillas rojas
def leftCheek(self, x, y): p>
tortuga.tracer(False)
t = self.t
self.noTrace_goto(x, y)
t.seth(300 )
t.fillcolor('#DD4D28')
t.begin_fill()
a = 2.3
para i en el rango (120):
si 0 lt; = i lt; 30 o 60 lt; = i 90:
a -= 0,05
t. lt(3)
t.fd(a)
más:
a = 0,05
t.lt(3)
t.fd(a)
t.end_fill()
tortuga.tracer(True)
def rightCheek(self, x , y):
t = self.t
tortuga.tracer(False)
self.noTrace_goto(x, y)
t.seth(60)
t.fillcolor('#DD4D28')
t.begin_fill()
a = 2.3
para i en rango(120):
if 0 lt; = i lt; = i 90:
a -= 0.05
t.lt(3)
t.fd(a)
más:
a = 0,05
t.lt(3)
t.fd(a )
t.end_fill()
tortuga.tracer(True)
def colorLeftEar(self, x, y):
t = self.t
self.noTrace_goto(x, y)
t.fillcolor('#000000')
t.begin_fill() p> p>
t.seth(330)
t.circle(100, 35)
t.seth(219)
t. círculo( -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('#000000')
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() p>
def cuerpo(self):
t = self.t
t.fillcolor('#F6D02F')
t.begin_fill( )
# Contorno de cara derecha
t.penup()
t.circle(130, 40)
t.pendown( )
t.circle(100, 105)
t.left(180)
t.circle(-100, 5)
#Oído derecho
t.seth(20)
t.circle(300, 30)
t.
círculo(30, 50)
t.seth(190)
t.circle(300, 36)
# Contorno superior
t.seth(150)
t.circle(150, 70)
# Oreja izquierda
t.seth(200)
t.circle(300, 40)
t.circle(30, 50)
t.seth(20)
t.circle(300 , 35)
#print(t.pos())
# Contorno de la cara izquierda
t.seth(240)
t.circle(105, 95)
t.left(180)
t.circle(-105, 5)
# Mano izquierda
t.seth(210)
t.circle(500, 18)
t.seth(200)
t.fd(10 )
t.seth(280)
t.fd(7)
t.seth(210)
t.fd ( 10)
t.seth(300)
t.circle(10, 80)
t.seth(220)
t.fd(10)
t.seth(300)
t.circle(10, 80)
t.seth(240) p >
t.fd(12)
t.seth(0)
t.fd(13)
t.seth(240)
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)< / p>
t.left(180)
t.circle(-500, 15)
t.seth(250)
t. círculo (100, 65)
# Pie izquierdo
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)
t.seth(60)
t.circle(-100, 20)
t.left(180)
t.circle(100, 20)
t.seth(300)
t.circle(10, 70)
t.seth(60)
t.circle(-100, 20)
t.left(180)
t. círculo(100, 20)
t.seth(10)
t.circle(100, 60)
# Horizontal
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)
# Pie derecho p>
t.seth(290)
t.circle(100, 55)
t.circle(10, 50)
t. seth(120)
t.circle(100, 20)
t.left(180)
t.circle(-100, 20) p> p>
t.seth(0)
t.circle(10, 50)
t.seth(110)
t. círculo( 100, 20)
t.left(180)
t.circle(-100, 20)
t.seth(30) p>
t.circle(20, 50)
t.seth(100)
t.circle(100, 40)
# Derecha Contorno lateral del cuerpo
t.seth(200)
t.circle(-100, 5)
t.left(180)
t.circle(100, 5)
t.left(30)
t.circle(100, 75)
t.right(15)
t.circle(-300, 21)
t.left(180)
t. círculo(300, 3)
# Mano derecha
t.seth(43)
t.circle(200, 60)
t.right(10)
t.fd(10)
t.circle(5, 160)
t.seth(90) p >
t.circle(5, 160)
t.seth(90)
t.fd(10)
t.seth( 90 )
t.circle(5, 180)
t.fd(10)
t.left(180)
t .left(20)
t.fd(10)
t.circle(5, 170)
t.fd(10)
t.seth(240)
t.circle(50, 30)
t.end_fill()
self.noTrace_goto(130, 125 )
t.seth(-20)
t.fd(5)
t.circle(-5, 160)
t.fd(5)
# Huella digital
self.noTrace_goto(166, 130)
t.seth(-90)
t.fd(3)
t.circle(-4, 180)
t.fd(3)
t.seth(- 90)
t.fd(3)
t.circle(-4, 180)
t.fd(3)
# Cola
self.noTrace_goto(168, 134)
t.fillcolor('#F6D02F')
t.begin_fill()
t.seth(40)
t.fd(200)
t.seth(-80)
t.fd(150)
t.seth(
210)
t.fd(150)
t.left(90)
t.fd(100)
t. derecha(95)
t.fd(100)
t.izquierda(110)
t.fd(70)
t.right(110)
t.fd(80)
t.left(110)
t.fd(30)
t.right(110)
t.fd(32)
t.right(106)
t.circle(100, 25)
t.right(15)
t.circle(-300, 2)
##############
#print(t.pos())
t.seth(30)
t.fd(40)
t. izquierda(100)
t.fd(70)
t.derecha(100)
t.fd(80)
t.left(100)
t.fd(46)
t.seth(66)
t.circle(200, 38)
t.right(10)
t.fd(10)
t.end_fill()
# Patrón de cola
t.fillcolor('#923E24')
self.noTrace_goto(126.82, -156.84)
t.begin_fill()
t.seth( 30)
t.fd(40)
t.left(100)
t.fd(40)
t. pencolor('#923e24')
t.seth(-30)
t.fd(30)
t.left(140)
t.fd(20)
t.right(150)
t.fd(20)
t.left(150)
t.fd(20)
t.right(150)
t.fd(20)
t.left(130 )
t.fd(18)
t.pencolor('#000000')
t.seth(-45)
t.fd(67)
t.right(110)
t.fd(80)
t.left(110)
t.fd(30)
t.right(110 )
t.fd(32)
t.right(106)
t.circle(100, 25)
t .right(15)
t.circle(-300, 2)
t.end_fill()
# Sombrero, ojos, boca, mejillas p>
self.cap(-134.07, 147.81)
self.boca(-5, 25)
self.leftCheek(-126, 32)
self.rightCheek(107, 63)
self.colorLeftEar(-250, 100)
self.colorRightEar(140, 270)
self .leftEye(-85, 90)
self.rightEye(50, 110)
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) p> p>
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) p>
t.right(20)
t.circle(200, 70)
t.circle(30, 60)
t.fd(70)
# print(t.pos())
t.right(35)
t.fd(50) p>
t.circle(8, 100)
t.
end_fill()
self.noTrace_goto(-168.47, 185.52)
t.seth(36)
t.circle(-270, 54) p> p>
t.left(180)
t.circle(270, 27)
t.circle(-80, 98)
t .fillcolor('#444444')
t.begin_fill()
t.left(180)
t.circle(80, 197) p>
t.left(58)
t.circle(200, 45)
t.end_fill()
self.noTrace_goto (- 58, 270)
t.pencolor('#228B22')
t.dot(35)
self.noTrace_goto(-30, 280 )
t.fillcolor('#228B22')
t.begin_fill()
t.seth(100)
t .círculo (30, 180)
t.seth(190)
t.fd(15)
t.seth(100)
t.circle(-45, 180)
t.right(90)
t.fd(15)
t.end_fill() p>
t.pencolor('#000000')
def inicio(self):
self.body()
def principal () :
print('Pintando el Pikachu... ')
tortuga.screensize(800, 600)
tortuga.title('Pikachu' )
pikachu = Pikachu()
pikachu.start()
tortuga.mainloop()
if __name__ == '__main__ ':
principal()