python-lottie  0.7.0+dev66cafb9
A framework to work with lottie files and telegram animated stickers (tgs)
colorize.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 import math
9 from lottie.utils import script
10 from lottie import objects
11 from lottie.parsers.svg import parse_svg_file
12 from lottie import Color
13 
14 last_frame = 60
15 an = parse_svg_file(os.path.join(
16  os.path.dirname(os.path.abspath(__file__)),
17  "blep.svg"
18 ), 0, last_frame)
19 
20 layer = an.find("durg")
21 
22 n_frames = 24
23 for fill in layer.find_all((objects.Fill, objects.Stroke)):
24  if isinstance(fill.color.value, list):
25  import pdb; pdb.set_trace(); pass
26  color = fill.color.value.converted(Color.Mode.LCH_uv)
27 
28  for frame in range(n_frames):
29  off = frame / (n_frames-1)
30  color.hue = (color.hue + math.tau / (n_frames-1)) % math.tau
31  fill.color.add_keyframe(off * last_frame, color.to_rgb())
32 
33 
34 script.script_main(an)
def parse_svg_file(file, layer_frames=0, *args, **kwargs)
Definition: importer.py:1324