python-lottie  0.7.0+devbe239c9
A framework to work with lottie files and telegram animated stickers (tgs)
flag.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.utils import animation as anutils
11 from lottie import Point, Color
12 
13 an = objects.Animation(60)
14 
15 layer = objects.ShapeLayer()
16 an.add_layer(layer)
17 g = layer.add_shape(objects.Group())
18 
19 sine_displacer = anutils.SineDisplacer(300, 50, 0, 60, 10, 1, 45)
20 # Keep the left side fixed
21 displacer = anutils.DisplacerDampener(sine_displacer, lambda p: p.x / 128 if p.x < 128 else 1)
22 
23 for i in range(0, 512+1, 16):
24  b = g.add_shape(objects.Ellipse())
25  b.size.value = Point(16, 16)
26  b.position.value = Point(i, 100)
27  displacer.animate_point(b.position)
28 
29 
30 bez = g.add_shape(objects.Path())
31 bez.shape.value.add_smooth_point(Point(256, 200), Point(50, 0))
32 bez.shape.value.add_smooth_point(Point(156, 300), Point(0, -50))
33 bez.shape.value.add_smooth_point(Point(256, 400), Point(-50, 0))
34 bez.shape.value.add_smooth_point(Point(356, 300), Point(0, 50))
35 bez.shape.value.close()
36 bez.shape.value.split_self_chunks(8)
37 displacer.animate_bezier(bez.shape)
38 
39 g.add_shape(objects.Fill(Color(1, 1, 0)))
40 
41 
42 g = layer.add_shape(objects.Group())
43 bez = g.add_shape(objects.Path())
44 g.add_shape(objects.Stroke(Color(1, 0, 0), 5))
45 g.add_shape(objects.Fill(Color(0, 0, 1)))
46 for i in range(9):
47  bez.shape.value.add_point(Point(i*64, 160), Point(-20, 0), Point(20, 0))
48 
49 for i in range(9):
50  bez.shape.value.add_point(Point(512-i*64, 420), Point(20, 0), Point(-20, 0))
51 bez.shape.value.close()
52 displacer.animate_bezier(bez.shape)
53 
54 
55 script.script_main(an)
56 
57 
def Point(x, y)
Definition: nvector.py:135