Exemplo n.º 1
0
 def test_to_tween(self):
     tween = Tween(3)
     tween.to(9, 11)
     self.assertEqual(len(tween), 11)
     expected = [3, 3.6, 4.2, 4.8, 5.4, 6.0, 6.6, 7.2, 7.8, 8.4, 9]
     for i, v in enumerate(tween):
         self.assertEqual(v, expected[i])
     self.assertEqual(i, 10)
Exemplo n.º 2
0
 def test_wait_tween(self):
     tween = Tween(5)
     tween.wait(10)
     self.assertEqual(len(tween), 10)
     self.assertEqual(tween.get(0), 5)
     self.assertEqual(tween.get(9), 5)
     self.assertEqual(tween[0], 5)
     self.assertEqual(tween[9], 5)
Exemplo n.º 3
0
 def test_ease_tween_length_1(self):
     tween = Tween(3)
     tween.ease(9, 1, test_linear())
     self.assertEqual(len(tween), 1)
     expected = [9]
     for i, v in enumerate(tween):
         self.assertAlmostEqual(v, expected[i])
     self.assertEqual(i, 0)
Exemplo n.º 4
0
 def test_ease_tween(self):
     tween = Tween(3)
     tween.ease(9, 10, test_linear())
     self.assertEqual(len(tween), 10)
     expected = [3.6, 4.2, 4.8, 5.4, 6.0, 6.6, 7.2, 7.8, 8.4, 9]
     for i, v in enumerate(tween):
         self.assertAlmostEqual(v, expected[i])
     self.assertEqual(i, 9)
Exemplo n.º 5
0
 def test_to_tween_length_1(self):
     tween = Tween(3)
     tween.to(9, 1)
     self.assertEqual(len(tween), 1)
     expected = [9]
     for i, v in enumerate(tween):
         self.assertAlmostEqual(v, expected[i])
     self.assertEqual(i, 0)
Exemplo n.º 6
0
 def plot_easing_function(ctx, x, y, fn):
     tw = Tween(0).ease(-100, 100, fn)
     poly = [(i, tw[i]) for i in range(100)]
     ctx.save()
     ctx.translate(x, y)
     Square(ctx).of_corner_size((0, -100), 100).stroke(Color(0.5), 2)
     Polygon(ctx).of_points(poly).open().stroke(Color('red'), 2)
     ctx.restore()
Exemplo n.º 7
0
 def test_set_tween(self):
     tween = Tween(3)
     tween.wait(6)
     tween.set(2.5, 8)
     self.assertEqual(len(tween), 14)
     self.assertEqual(tween.get(0), 3)
     self.assertEqual(tween[5], 3)
     self.assertEqual(tween[6], 2.5)
     self.assertEqual(tween.get(13), 2.5)
     expected = [3, 3, 3, 3, 3, 3, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5]
     for i, v in enumerate(tween):
         self.assertEqual(v, expected[i])
     self.assertEqual(i, 13)
Exemplo n.º 8
0
 def test_empty_tween(self):
     tween = Tween()
     self.assertEqual(len(tween), 0)
Exemplo n.º 9
0
 def test_ease_tween_length_0(self):
     tween = Tween(3)
     tween.ease(9, 0, test_linear())
     self.assertEqual(len(tween), 0)
Exemplo n.º 10
0
 def test_to_tween_length_0(self):
     tween = Tween(3)
     tween.to(9, 0)
     self.assertEqual(len(tween), 0)
Exemplo n.º 11
0
from generativepy.tween import Tween

# Create a tween
tween = Tween(3.0).wait(4).to(13.0, 5).wait(2).set(7.0, 4)

# You can use len() to fund the length of the tween in frames
print('Length = ', len(tween))

# You can access the vale#ue for a particular frame using indexing []
# or the get() function.
print('tween[7] = ', tween[5])
print('tween[8] = ', tween.get(7))

# The tween can be accessed as a sequence. Here we use a list
# comprehension to convert the values to strings that print the
# entire sequence
strings = [str(x) for x in tween]
print(', '.join(strings))