python-lottie  0.6.10+dev2509936
A framework to work with lottie files and telegram animated stickers (tgs)
shape_to_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 
12 
13 an = objects.Animation(60)
14 
15 layer = objects.ShapeLayer()
16 an.add_layer(layer)
17 
18 shapes = layer.add_shape(objects.Group())
19 
20 circle = shapes.add_shape(objects.Ellipse())
21 circle.size.add_keyframe(0, Point(100, 100))
22 circle.size.add_keyframe(30, Point(50, 120))
23 circle.size.add_keyframe(60, Point(100, 100))
24 circle.position.add_keyframe(0, Point(220, 110))
25 circle.position.add_keyframe(20, Point(180, 110))
26 circle.position.add_keyframe(40, Point(220, 110))
27 
28 star = shapes.add_shape(objects.Star())
29 star.inner_radius.add_keyframe(0, 20)
30 star.inner_radius.add_keyframe(30, 50)
31 star.inner_radius.add_keyframe(60, 20)
32 star.outer_radius.value = 50
33 #star.inner_roundness.value = 100
34 #star.outer_roundness.value = 40
35 star.rotation.value = 45
36 star.position.value = Point(330, 110)
37 
38 rect = shapes.add_shape(objects.Rect())
39 rect.size.add_keyframe(0, Point(100, 100))
40 rect.size.add_keyframe(30, Point(50, 120))
41 rect.size.add_keyframe(60, Point(100, 100))
42 rect.position.add_keyframe(0, Point(110, 110))
43 rect.position.add_keyframe(20, Point(80, 110))
44 rect.position.add_keyframe(40, Point(110, 110))
45 
46 
47 rrect = shapes.add_shape(objects.Rect())
48 rrect.size.value = Point(100, 100)
49 rrect.position.value = Point(440, 110)
50 rrect.rounded.add_keyframe(0, 0)
51 rrect.rounded.add_keyframe(30, 30)
52 rrect.rounded.add_keyframe(60, 0)
53 
54 fill = shapes.add_shape(objects.Fill(Color(1, 1, 0)))
55 stroke = shapes.add_shape(objects.Stroke(Color(0, 0, 0), 5))
56 
57 
58 beziers = layer.add_shape(objects.Group())
59 beziers.transform.position.value = Point(0, 130)
60 beziers.add_shape(rect.to_bezier())
61 beziers.add_shape(rrect.to_bezier())
62 beziers.add_shape(circle.to_bezier())
63 beziers.add_shape(star.to_bezier())
64 
65 
66 
67 fill = beziers.add_shape(objects.Fill(Color(0, 0, 1)))
68 stroke = beziers.add_shape(objects.Stroke(Color(1, 1, 1), 5))
69 
70 
71 script.script_main(an)
lottie.nvector.Point
def Point(x, y)
Definition: nvector.py:135
lottie.utils
Definition: __init__.py:1