python-lottie  0.6.10+dev2509936
A framework to work with lottie files and telegram animated stickers (tgs)
auto_orient.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 layer = objects.ShapeLayer()
18 an.add_layer(layer)
19 layer.auto_orient = True
20 
21 group = layer.add_shape(objects.Group())
22 star = objects.Star()
23 star.inner_radius.value = 20
24 star.outer_radius.value = 50
25 star.position.value = Point(0, 0)
26 group.add_shape(star)
27 
28 group.add_shape(objects.Ellipse(NVector(0, 35), NVector(16, 16)))
29 
30 layer.add_shape(objects.Fill(Color(1, 1, 0)))
31 
32 
33 tl = 120
34 layer.transform.position.add_keyframe(last_frame/4*0, Point(+50, 256), out_tan=NVector(0, -tl), in_tan=NVector(-tl, 0))
35 layer.transform.position.add_keyframe(last_frame/4*1, Point(256, +50), out_tan=NVector(+tl, 0), in_tan=NVector(0, -tl))
36 layer.transform.position.add_keyframe(last_frame/4*2, Point(462, 256), out_tan=NVector(0, +tl), in_tan=NVector(+tl, 0))
37 layer.transform.position.add_keyframe(last_frame/4*3, Point(256, 462), out_tan=NVector(-tl, 0), in_tan=NVector(0, +tl))
38 layer.transform.position.add_keyframe(last_frame/4*4, Point(+50, 256), out_tan=NVector(0, -tl), in_tan=NVector(-tl, 0))
39 
40 
41 layer1 = objects.ShapeLayer()
42 an.add_layer(layer1)
43 layer1.add_shape(group)
44 layer1.add_shape(objects.Fill(Color(1, 0, 0)))
45 layer1.transform = layer.transform
46 
47 
48 bg = an.add_layer(objects.ShapeLayer())
49 track = bg.add_shape(objects.Path()).shape.value
50 track.closed = True
51 track.add_point(Point(+50, 256), NVector(0, +tl), NVector(0, -tl))
52 track.add_point(Point(256, +50), NVector(-tl, 0), NVector(+tl, 0))
53 track.add_point(Point(462, 256), NVector(0, -tl), NVector(0, +tl))
54 track.add_point(Point(256, 462), NVector(+tl, 0), NVector(-tl, 0))
55 bg.add_shape(objects.Stroke(Color(0, 0, 1), 50))
56 
57 
58 script.script_main(an)
59 
lottie.nvector.Point
def Point(x, y)
Definition: nvector.py:135
lottie.utils
Definition: __init__.py:1