python-lottie  0.6.10+dev2509936
A framework to work with lottie files and telegram animated stickers (tgs)
bezier.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
11 from lottie.utils import color
12 
13 
14 an = objects.Animation(59)
15 
16 layer = objects.ShapeLayer()
17 an.add_layer(layer)
18 
19 heart = objects.Bezier()
20 heart.add_point(Point(50, 20), Point(50, -20), Point(-50, -20))
21 heart.add_smooth_point(Point(0, 50), Point(-5, -10))
22 heart.add_smooth_point(Point(50, 100), Point(-10, 0))
23 heart.add_smooth_point(Point(100, 50), Point(-5, 10))
24 heart.closed = True
25 antiheart = (
26  objects.Bezier()
27  .add_smooth_point(Point(50, 0), Point(10, 0))
28  .add_smooth_point(Point(0, 50), Point(0, -20))
29  .add_point(Point(50, 80), Point(-50, 20), Point(50, 20))
30  .add_smooth_point(Point(100, 50), Point(0, 20))
31  .close()
32 )
33 
34 g1 = layer.add_shape(objects.Group())
35 g1.transform.position.value = Point(100, 200)
36 shape = g1.add_shape(objects.Path())
37 shape.shape.value = heart
38 
39 g2 = layer.add_shape(objects.Group())
40 g2.transform.position.value = Point(300, 200)
41 animated = g2.add_shape(objects.Path())
42 animated.shape.add_keyframe(0, heart)
43 animated.shape.add_keyframe(30, antiheart)
44 animated.shape.add_keyframe(59, heart)
45 
46 
47 fill = layer.add_shape(objects.Fill(color.from_uint8(255, 0, 0)))
48 stroke = layer.add_shape(objects.Stroke(Color(0, 0, 0), 5))
49 
50 
51 script.script_main(an)
lottie.nvector.Point
def Point(x, y)
Definition: nvector.py:135
lottie.utils
Definition: __init__.py:1