python-lottie  0.7.0+devbe239c9
A framework to work with lottie files and telegram animated stickers (tgs)
3d_face.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 Size, Point3D, Point, Color
13 
14 
15 an = objects.Animation(120)
16 
17 layer = objects.ShapeLayer()
18 an.add_layer(layer)
19 
20 g = layer.add_shape(objects.Group())
21 b = g.add_shape(objects.Ellipse())
22 b.size.value = Size(256, 256)
23 b.position.value = Point(256, 256)
24 g.add_shape(objects.Fill(Color(1, 1, 0)))
25 
26 g = layer.insert_shape(0, objects.Group())
27 eye1 = g.add_shape(objects.Ellipse())
28 eye1.size.value = Size(20, 20)
29 eye1.position.value = Point3D(256-50, 256-50, -100)
30 g.add_shape(objects.Fill(Color(0, 0, 0)))
31 
32 g = layer.insert_shape(0, objects.Group())
33 eye2 = g.add_shape(objects.Ellipse())
34 eye2.size.value = Size(20, 20)
35 eye2.position.value = Point3D(256+50, 256-50, -100)
36 g.add_shape(objects.Fill(Color(0, 0, 0)))
37 
38 g = layer.insert_shape(0, objects.Group())
39 nose = g.add_shape(objects.Ellipse())
40 nose.size.value = Size(64, 64)
41 nose.position.value = Point3D(256, 256+10, -150)
42 g.add_shape(objects.Fill(Color(1, 0, 0)))
43 
44 
45 g = layer.insert_shape(0, objects.Group())
46 mouth = g.add_shape(objects.Path())
47 bez = mouth.shape.value
48 bez.add_smooth_point(Point3D(256-80, 256+30, -80), Point3D(0, 0, 0))
49 bez.add_smooth_point(Point3D(256, 256+70, -100), -Point3D(50, 0, 0))
50 bez.add_smooth_point(Point3D(256+80, 256+30, -80), Point3D(0, 0, 0))
51 g.add_shape(objects.Stroke(Color(1, 0, 0), 2))
52 
53 # Animate the circles using depth rotation
54 dr = anutils.DepthRotationDisplacer(Point3D(256, 256, 0), 0, 30, 10, Point3D(0, 4, 1), 0, 30)
55 dr.animate_point(eye1.position)
56 dr.animate_point(eye2.position)
57 dr.animate_point(nose.position)
58 dr.animate_bezier(mouth.shape)
59 
60 dr = anutils.DepthRotationDisplacer(Point3D(256, 256, 0), 30, 90, 10, Point3D(0, 4, 1), 0, -60)
61 dr.animate_point(eye1.position)
62 dr.animate_point(eye2.position)
63 dr.animate_point(nose.position)
64 dr.animate_bezier(mouth.shape)
65 
66 dr = anutils.DepthRotationDisplacer(Point3D(256, 256, 0), 90, 120, 10, Point3D(0, 4, 1), 0, 30)
67 dr.animate_point(eye1.position)
68 dr.animate_point(eye2.position)
69 dr.animate_point(nose.position)
70 dr.animate_bezier(mouth.shape)
71 
72 
73 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