python-lottie  0.6.10+dev2509936
A framework to work with lottie files and telegram animated stickers (tgs)
layers.py
1 #!/usr/bin/env python3
2 import sys
3 import os
4 sys.path.insert(0, os.path.join(
5  os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
6  "lib"
7 ))
8 from lottie.utils import script
9 from lottie import objects
10 from lottie import Point, Color, NVector
11 
12 
13 last_frame = 180
14 an = objects.Animation(last_frame)
15 
16 
17 base = an.add_layer(objects.NullLayer())
18 base.transform.anchor_point.value = base.transform.position.value = Point(256, 256)
19 base.transform.rotation.add_keyframe(0, 0)
20 base.transform.rotation.add_keyframe(last_frame, 360)
21 
22 
23 star_layer = objects.ShapeLayer()
24 base.add_child(star_layer)
25 star = star_layer.add_shape(objects.Star())
26 star.inner_radius.value = 20
27 star.outer_radius.value = 50
28 star.position.value = Point(50, 50)
29 star_layer.add_shape(objects.Fill(Color(1, 1, 0)))
30 star_layer.add_shape(objects.Stroke(Color(0, 0, 0), 5))
31 star_layer.transform.anchor_point = star.position
32 star_layer.transform.position.value = Point(50, 256)
33 star_layer.transform.rotation.add_keyframe(0, 0)
34 star_layer.transform.rotation.add_keyframe(last_frame, -360)
35 
36 
37 circle_layer = objects.ShapeLayer()
38 an.add_layer(circle_layer)
39 circle_layer.parent = base
40 circle = circle_layer.add_shape(objects.Ellipse())
41 circle.size.value = NVector(100, 100)
42 circle_layer.add_shape(objects.Fill(Color(1, 0, 0)))
43 circle_layer.add_shape(objects.Stroke(Color(0, 0, 0), 5))
44 circle_layer.transform.position.add_keyframe(0, Point(256, 512-50))
45 circle_layer.transform.position.add_keyframe(last_frame/2, Point(256, 50))
46 circle_layer.transform.position.add_keyframe(last_frame, Point(256, 512-50))
47 
48 
49 scl = base.add_child(objects.SolidColorLayer("#0000ff"))
50 scl.transform.scale.value.x *= 0.2
51 scl.transform.position.value.x = 205
52 
53 
54 star_background = star_layer.add_child(objects.SolidColorLayer("#0000ff", 100, 100))
55 
56 
57 script.script_main(an)
58 
lottie.nvector.Point
def Point(x, y)
Definition: nvector.py:135
lottie.utils
Definition: __init__.py:1