python-lottie  0.7.0+devbe239c9
A framework to work with lottie files and telegram animated stickers (tgs)
easing.py
1 #!/usr/bin/env python3
2 import sys
3 import os
4 import math
5 sys.path.insert(0, os.path.join(
6  os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
7  "lib"
8 ))
9 from lottie.utils import script
10 from lottie import objects
11 from lottie.objects import easing
12 from lottie import Point, Color, Size
13 
14 an = objects.Animation(180)
15 
16 layer = objects.ShapeLayer()
17 an.add_layer(layer)
18 
19 easings = [
20  (easing.Linear(), Color(1, 1, 1)),
21  (easing.Jump(), Color(0, 0, 0)),
22  (easing.EaseOut(1), Color(1, 0, 0)),
23  (easing.EaseOut(1 / 2), Color(1 / 2, 0, 0)),
24  (easing.EaseOut(1 / 3), Color(1 / 3, 0, 0)),
25  (easing.EaseOut(1 / 5), Color(1 / 5, 0, 0)),
26  (easing.EaseOut(1 / 10), Color(1 / 19, 0, 0)),
27  (easing.EaseIn(1), Color(0, 1, 0)),
28  (easing.EaseIn(1 / 2), Color(0, 1 / 2, 0)),
29  (easing.EaseIn(1 / 3), Color(0, 1 / 3, 0)),
30  (easing.EaseIn(1 / 5), Color(0, 1 / 5, 0)),
31  (easing.EaseIn(1 / 10), Color(0, 1 / 10, 0)),
32  (easing.Sigmoid(1), Color(0, 0, 1)),
33  (easing.Sigmoid(1 / 2), Color(0, 0, 1 / 2)),
34  (easing.Sigmoid(1 / 3), Color(0, 0, 1 / 3)),
35  (easing.Sigmoid(1 / 5), Color(0, 0, 1 / 5)),
36  (easing.Sigmoid(1 / 10), Color(0, 0, 1 / 10)),
37 ]
38 height = 512 / len(easings)
39 width = height
40 
41 for i in range(len(easings)):
42  group = layer.add_shape(objects.Group())
43 
44  rectgroup = group.add_shape(objects.Group())
45  rect = rectgroup.add_shape(objects.Rect())
46  rect.size.value = Size(width, height)
47  y = i * height + height / 2
48  group.transform.position.add_keyframe(0, Point(width / 2, y), easings[i][0])
49  group.transform.position.add_keyframe(90, Point(512 - width / 2, y), easings[i][0])
50  group.transform.position.add_keyframe(180, Point(width / 2, y), easings[i][0])
51  rectgroup.add_shape(objects.Fill(easings[i][1]))
52 
53  bezgroup = group.insert_shape(0, objects.Group())
54  bez = group.transform.position.keyframes[0].bezier()
55  bezgroup.transform.scale.value = Size(100*width, -100*height)
56  bezgroup.transform.position.value = Point(-width/2, width/2)
57  bezgroup.add_shape(objects.Path()).shape.value = bez
58  sc = Color(0, 0, 0) if easings[i][1].length == math.sqrt(3) else Color(1, 1, 1)
59  bezgroup.add_shape(objects.Stroke(sc, 0.1))
60 
61 
62 
63 script.script_main(an)
def Point(x, y)
Definition: nvector.py:135
def Size(x, y)
Definition: nvector.py:139
Package with all the Lottie Python bindings.
Definition: __init__.py:1