python-lottie  0.7.0+dev66cafb9
A framework to work with lottie files and telegram animated stickers (tgs)
3d_rotation.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 Point, Color, Point3D, Size
13 
14 an = objects.Animation(120)
15 
16 layer = objects.ShapeLayer()
17 an.add_layer(layer)
18 
19 # Build a sphere out of circles
20 balls = []
21 axes = [
22  Point(1, 0),
23  Point(0, 1),
24 ]
25 for i in range(20):
26  a = i/20 * math.pi * 2
27  for axis in axes:
28  g = layer.add_shape(objects.Group())
29  b = g.add_shape(objects.Ellipse())
30  b.size.value = Size(20, 20)
31  xz = axis * math.sin(a)*128
32  pos = Point3D(256+xz[0], 256+math.cos(a)*128, xz[1])
33  b.position.value = pos
34  balls.append(b)
35  g.add_shape(objects.Fill(Color(0, 1, 0)))
36 
37 # Animate the circles using depth rotation
38 dr = anutils.DepthRotationDisplacer(Point3D(256, 256, 0), 0, 120, 10, Point3D(0, 2, -1))
39 for b in balls:
40  dr.animate_point(b.position)
41 
42 script.script_main(an)
def Point3D(x, y, z)
Definition: nvector.py:143
def Point(x, y)
Definition: nvector.py:135
def Size(x, y)
Definition: nvector.py:139