python-lottie  0.6.10+dev2509936
A framework to work with lottie files and telegram animated stickers (tgs)
gradients.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, NVector
10 from lottie import Color, Point
11 
12 
13 an = objects.Animation(59)
14 
15 layer = objects.ShapeLayer()
16 an.add_layer(layer)
17 
18 g1 = layer.add_shape(objects.Group())
19 
20 circle = g1.add_shape(objects.Ellipse())
21 circle.size.value = Point(100, 100)
22 circle.position.value = Point(128, 156)
23 
24 
25 fill = g1.add_shape(objects.GradientFill())
26 fill.start_point.value = Point(100, 0)
27 fill.end_point.value = Point(200, 0)
28 fill.colors.set_stops([(0, Color(1, 0, 0)), (1, Color(1, 1, 0))])
29 
30 
31 stroke = g1.add_shape(objects.GradientStroke(5))
32 stroke.start_point.value = Point(100, 0)
33 stroke.end_point.value = Point(200, 0)
34 stroke.colors.add_keyframe( 0, [(0, Color(1, 0, 0)), (1, Color(1, 1, 0))])
35 stroke.colors.add_keyframe(10, [(0, Color(1, 1, 0)), (1, Color(0, 1, 0))])
36 stroke.colors.add_keyframe(30, [(0, Color(1, 0, 1)), (1, Color(0, 0, 1))])
37 stroke.colors.add_keyframe(59, [(0, Color(1, 0, 0)), (1, Color(1, 1, 0))])
38 stroke.colors.count = 2
39 stroke.width.value = 10
40 
41 
42 g2 = layer.add_shape(objects.Group())
43 
44 circle = g2.add_shape(objects.Ellipse())
45 circle.size.value = Point(200, 200)
46 circle.position.value = Point(128+256, 256)
47 
48 
49 fill = g2.add_shape(objects.GradientFill())
50 fill.gradient_type = objects.GradientType.Radial
51 fill.start_point.value = Point(128+256, 256)
52 fill.end_point.value = Point(128+256+100, 256)
53 fill.colors.set_stops([(0, Color(1, 0, 0)), (1, Color(1, 1, 0))])
54 #fill.highlight_length.add_keyframe(0, -50)
55 #fill.highlight_length.add_keyframe(30, 50)
56 #fill.highlight_length.add_keyframe(59, -50)
57 #fill.highlight_angle.value = 45
58 fill.highlight_length.value = 90
59 
60 
61 g3 = layer.add_shape(objects.Group())
62 circle = g3.add_shape(objects.Ellipse())
63 circle.size.value = Point(100, 100)
64 circle.position.value = Point(128, 356)
65 fill = g3.add_shape(objects.GradientFill())
66 fill.start_point.value = Point(100, 0)
67 fill.end_point.value = Point(200, 0)
68 fill.colors.set_stops([(0, NVector(1, 0, 0, 1)), (0.5, NVector(1, .5, 0, 1)), (1, NVector(1, 1, 0, 0))])
69 
70 
71 script.script_main(an)
lottie.nvector.Point
def Point(x, y)
Definition: nvector.py:135
lottie.utils
Definition: __init__.py:1