python-lottie  0.6.10+dev2509936
A framework to work with lottie files and telegram animated stickers (tgs)
precomp.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 NVector, Color
11 
12 
13 an = objects.Animation(80)
14 
15 precomp = objects.Precomp("myid", an)
16 
17 # Define stuff in the precomposition (a circle moving left to right)
18 layer = objects.ShapeLayer()
19 precomp.add_layer(layer)
20 layer.out_point = 60
21 
22 circle = layer.add_shape(objects.Ellipse())
23 circle.size.value = NVector(100, 100)
24 circle.position.add_keyframe(0, NVector(-50, 50))
25 circle.position.add_keyframe(60, NVector(512+50, 50))
26 
27 fill = layer.add_shape(objects.Fill())
28 fill.color.add_keyframe(0, Color(1, 1, 0))
29 fill.color.add_keyframe(60, Color(1, 0, 0))
30 
31 
32 # plays the precomp as it is
33 pcl0 = an.add_layer(objects.PreCompLayer("myid"))
34 
35 # plays the precomp, offset in time by 20 frames and in space by 100 pixels
36 pcl1 = an.add_layer(objects.PreCompLayer("myid"))
37 pcl1.start_time = 20
38 pcl1.transform.position.value = NVector(0, 100)
39 
40 # playes the composition, but starts it with negative time, so it's farther ahead
41 pcl2 = an.add_layer(objects.PreCompLayer("myid"))
42 pcl2.start_time = -20
43 pcl2.transform.position.value = NVector(0, 200)
44 
45 # another instance on the same position as the one before
46 # but with a different time offset, to make the animation loop
47 pcl3 = an.add_layer(objects.PreCompLayer("myid"))
48 pcl3.start_time = 60
49 pcl3.transform.position.value = NVector(0, 200)
50 
51 # Uses time remapping to have more fine tuning on the animation
52 # (goes forward for 40 frames, than backwards)
53 pcl4 = an.add_layer(objects.PreCompLayer("myid"))
54 pcl4.transform.position.value = NVector(0, 300)
55 pcl4.time_remapping = objects.Value()
56 pcl4.time_remapping.add_keyframe(0, 0.1)
57 pcl4.time_remapping.add_keyframe(40, 0.5)
58 pcl4.time_remapping.add_keyframe(80, 0.1)
59 
60 # Same effect as pcl2+pcl3 but using a single layer and time remapping
61 pcl5 = an.add_layer(objects.PreCompLayer("myid"))
62 pcl5.transform.position.value = NVector(0, 400)
63 pcl5.time_remapping = objects.Value()
64 pcl5.time_remapping.add_keyframe(0, 0.333)
65 pcl5.time_remapping.add_keyframe(59, 1.333, objects.easing.Jump())
66 pcl5.time_remapping.add_keyframe(60, 0)
67 pcl5.time_remapping.add_keyframe(80, 0.333)
68 
69 script.script_main(an)
70 
lottie.utils
Definition: __init__.py:1