python-lottie  0.7.0+dev66cafb9
A framework to work with lottie files and telegram animated stickers (tgs)
coin.py
1 #!/usr/bin/env python3
2 import sys
3 import os
4 import math
5 sys.path.insert(0, os.path.join(
6  os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
7  "lib"
8 ))
9 from lottie.utils import script
10 from lottie import objects
11 from lottie.utils import animation as anutils
12 from lottie import Color, Point
13 from lottie.objects import easing
14 
15 
16 rot_time = 45
17 an = objects.Animation(rot_time*4)
18 
19 
20 layer = objects.ShapeLayer()
21 an.add_layer(layer)
22 
23 
24 def add_shape(shape, color, parent):
25  g = parent.add_shape(objects.Group())
26  s = g.add_shape(shape)
27  g.add_shape(objects.Fill(color))
28  return s
29 
30 
31 face1 = add_shape(objects.Ellipse(), Color(1, 1, 0), layer)
32 face2 = add_shape(objects.Ellipse(), Color(0, 1, 0), layer)
33 
34 side = layer.add_shape(objects.Group())
35 side1 = add_shape(objects.Ellipse(), Color(1, 0, 0), side)
36 side2 = add_shape(objects.Ellipse(), Color(1, 0, 0), side)
37 sider = add_shape(objects.Rect(), Color(1, 0, 0), side)
38 
39 
40 width = 10
41 
42 face1.size.add_keyframe(rot_time*0, Point(256, 256), easing.EaseIn())
43 face1.size.add_keyframe(rot_time*1, Point(0, 256))
44 face1.size.add_keyframe(rot_time*2, Point(0, 256))
45 face1.size.add_keyframe(rot_time*3, Point(0, 256), easing.EaseOut())
46 face1.size.add_keyframe(rot_time*4, Point(256, 256))
47 face1.position.add_keyframe(rot_time*0, Point(256, 256), easing.EaseIn())
48 face1.position.add_keyframe(rot_time*1, Point(256-width, 256))
49 face1.position.add_keyframe(rot_time*2, Point(256-width, 256))
50 face1.position.add_keyframe(rot_time*3, Point(256+width, 256), easing.EaseOut())
51 face1.position.add_keyframe(rot_time*4, Point(256, 256))
52 
53 
54 face2.size.add_keyframe(rot_time*0, Point(0, 256))
55 face2.size.add_keyframe(rot_time*1, Point(0, 256), easing.EaseOut())
56 face2.size.add_keyframe(rot_time*2, Point(256, 256), easing.EaseIn())
57 face2.size.add_keyframe(rot_time*3, Point(0, 256))
58 face2.position.add_keyframe(rot_time*0, Point(256+width, 256))
59 face2.position.add_keyframe(rot_time*1, Point(256+width, 256), easing.EaseOut())
60 face2.position.add_keyframe(rot_time*2, Point(256, 256), easing.EaseIn())
61 face2.position.add_keyframe(rot_time*3, Point(256-width, 256))
62 
63 
64 side1.size = face1.size
65 side1.position.add_keyframe(rot_time*0, Point(256, 256), easing.EaseIn())
66 side1.position.add_keyframe(rot_time*1, Point(256+width, 256))
67 side1.position.add_keyframe(rot_time*2, Point(256-width, 256))
68 side1.position.add_keyframe(rot_time*3, Point(256-width, 256), easing.EaseOut())
69 side1.position.add_keyframe(rot_time*4, Point(256, 256))
70 
71 sider.position.value = Point(256, 256)
72 sider.size.add_keyframe(rot_time*0, Point(0, 256))
73 sider.size.add_keyframe(rot_time*1, Point(2*width, 256))
74 sider.size.add_keyframe(rot_time*2, Point(0, 256))
75 sider.size.add_keyframe(rot_time*3, Point(2*width, 256))
76 
77 side2.size = face2.size
78 side2.position.add_keyframe(rot_time*0, Point(256-width, 256))
79 side2.position.add_keyframe(rot_time*1, Point(256-width, 256), easing.EaseOut())
80 side2.position.add_keyframe(rot_time*2, Point(256, 256), easing.EaseIn())
81 side2.position.add_keyframe(rot_time*3, Point(256+width, 256))
82 side2.position.add_keyframe(rot_time*4, Point(256-width, 256))
83 
84 
85 script.script_main(an)
def Point(x, y)
Definition: nvector.py:135
Package with all the Lottie Python bindings.
Definition: __init__.py:1