python-lottie  0.6.10+dev2509936
A framework to work with lottie files and telegram animated stickers (tgs)
follow_path.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.animation import follow_path
11 from lottie import Point, Color
12 
13 an = objects.Animation(180)
14 
15 layer = objects.ShapeLayer()
16 an.add_layer(layer)
17 
18 group = layer.add_shape(objects.Group())
19 ball = group.add_shape(objects.Ellipse())
20 ball.size.value = Point(10, 10)
21 
22 r1 = group.add_shape(objects.Rect())
23 r1.size.value = Point(50, 10)
24 
25 r2 = group.add_shape(objects.Group())
26 r2.add_shape(objects.Rect()).size.value = Point(50, 10)
27 r2 = r2.transform
28 
29 group.add_shape(objects.Fill(Color(0, 1, 0)))
30 
31 group = layer.add_shape(objects.Group())
32 bez = group.add_shape(objects.Path())
33 bez.shape.value.add_point(Point(256, 128), Point(0, 0), Point(64, 64))
34 bez.shape.value.add_point(Point(256, 256), Point(-64, -64), Point(-64, 64))
35 bez.shape.value.add_point(Point(256, 256+120), Point(0, 0), Point(0, 0))
36 group.add_shape(objects.Stroke(Color(1, 0, 0), 10))
37 
38 follow_path(ball.position, bez.shape.value, 0, 90, 30, False, Point(0, 0))
39 follow_path(ball.position, bez.shape.value, 90, 180, 30, True, Point(0, 0))
40 
41 follow_path(r1.position, bez.shape.value, 0, 90, 30, False, Point(150, 0))
42 follow_path(r1.position, bez.shape.value, 90, 180, 30, True, Point(150, 0))
43 
44 follow_path(r2.position, bez.shape.value, 0, 90, 30, False, Point(-150, 0), 0, r2.rotation, 90)
45 follow_path(r2.position, bez.shape.value, 90, 180, 30, True, Point(-150, 0), 0, r2.rotation, 90)
46 
47 script.script_main(an)
lottie.utils.animation
Definition: animation.py:1
lottie.nvector.Point
def Point(x, y)
Definition: nvector.py:135
lottie.utils
Definition: __init__.py:1
lottie.utils.animation.follow_path
def follow_path(position_prop, bezier, start_time, end_time, n_keyframes, reverse=False, offset=NVector(0, 0), start_t=0, rotation_prop=None, rotation_offset=0)
Definition: animation.py:58