Animation and Transformation in pyleap
Transformation is all about changing the scale(changing the size): The default value is 1. We can scale from 0 to 1.
1. scale (scaling both x and y values)
# both x and y value of object will be scaled to 0.5
object.scale = 0.5
2. scale_x (horizontal scale of the sprite)
# x value of the object will be scaled to 0.4
object.scale_x = 0.4
3. scale_y (vertical scale of the sprite)
# y value of the object will be scaled to 0.8
object.scale_y = 0.8
Project: School Bus
Source code:
from pyleap import*
#body
window.set_size(1000,400)
r = Rectangle(0,0,800,400,'black')
r1 = Rectangle(150,100,410,150,'orange')
r2 = Rectangle(250,250,310,110,'orange')
#text
tt = Text('SCHOOL BUS', 400, 200, font_size=13, color='white')
#tyre
c1 = Circle(220,100,50,'black')
c12 = Circle(220,100,40,'#b2beb5')
c13 = Circle(220,100,20,'white')
c2 = Circle(480,100,50,'black')
c21 = Circle(480,100,40,'#b2beb5')
c22 = Circle(480,100,20,'white')
#window
w1 = Rectangle(260,250,40,100,'white')
w2 = Rectangle(310,250,50,100,'white')
w3 = Rectangle(370,250,50,100,'white')
w4 = Rectangle(430,250,50,100,'white')
w5 = Rectangle(490,250,50,100,'white')
#door
d = Rectangle(310,150,50,200,'black')
#light
t = Circle(180,220,20,'white')
t1 = Circle(170,175,10,'red')
t2 = Circle(167,140,13,'red')
tb1 = Circle(540,175,10,'red')
tb2 = Circle(540,140,13,'red')
#two rectangle
l = Rectangle(400,230,120,5,'black')
ld = Rectangle(400,220,120,5,'black')
#door lock
dl = Rectangle(325,230,15,5,'black')
#signal light
s = Rectangle(552,280,10,33,'red')
#road
road = Rectangle(0,40,1000,20,'gray')
rr1 = Rectangle(0,45,20,10,'white')
rr2 = Rectangle(100,45,20,10,'white')
rr3 = Rectangle(200,45,20,10,'white')
rr4 = Rectangle(300,45,20,10,'white')
rr5 = Rectangle(400,45,20,10,'white')
rr6 = Rectangle(500,45,20,10,'white')
rr7 = Rectangle(600,45,20,10,'white')
rr8 = Rectangle(700,45,20,10,'white')
rr9 = Rectangle(800,45,20,10,'white')
rr10 = Rectangle(900,45,20,10,'white')
rr11 = Rectangle(1000,45,20,10,'white')
def Loop(dt):
r.draw()
r1.draw()
r1.x = r1.x-1
r2.draw()
r2.x = r2.x-1
c1.draw()
c1.x = c1.x-1
c12.draw()
c12.x = c12.x-1
c13.draw()
c13.x = c13.x-1
c2.draw()
c2.x = c2.x-1
c21.draw()
c21.x = c21.x-1
c22.draw()
c22.x = c22.x-1
w1.draw()
w1.x = w1.x-1
w2.draw()
w2.x = w2.x-1
w3.draw()
w3.x = w3.x-1
w4.draw()
w4.x = w4.x-1
w5.draw()
w5.x = w5.x-1
d.stroke()
d.x = d.x-1
t.draw()
t.x = t.x-1
t1.draw()
t1.x = t1.x-1
t2.draw()
t2.x = t2.x-1
tb1.draw()
tb1.x = tb1.x-1
tb2.draw()
tb2.x = tb2.x-1
l.draw()
l.x = l.x-1
ld.draw()
ld.x = ld.x-1
s.draw()
s.x = s.x-1
dl.draw()
dl.x = dl.x-1
tt.draw()
tt.x = tt.x-1
road.draw()
rr1.draw()
rr2.draw()
rr3.draw()
rr4.draw()
rr5.draw()
rr6.draw()
rr7.draw()
rr8.draw()
rr9.draw()
rr10.draw()
rr11.draw()
repeat(Loop)
run()
Output: