### Example Usage Source: https://mattbas.gitlab.io/python-lottie/wagging_8py-example.html This snippet demonstrates the setup and main script execution for the wagging_8py example. ```python 76setup(256, 1) 77setup(256+128, 2) 80script.script_main(an) ``` -------------------------------- ### Install from local sources Source: https://mattbas.gitlab.io/python-lottie/index.html Install the lottie package from a local source directory. ```bash pip install /path/to/the/sources # this is the path where setup.py is located ``` -------------------------------- ### Install from PyPI Source: https://mattbas.gitlab.io/python-lottie/index.html Install the lottie package from the Python Package Index. ```bash pip install lottie ``` -------------------------------- ### Install requirements from source Source: https://mattbas.gitlab.io/python-lottie/index.html Installs all requirements listed in the requirements.txt file when installing from source (excluding pypotrace). ```bash pip install -r requirements.txt ``` -------------------------------- ### Precomp Example Source: https://mattbas.gitlab.io/python-lottie/precomp_8py-example.html This example demonstrates how to create and use precompositions within the python-lottie framework. It defines a precomposition with a moving circle and then instances it multiple times with different transformations and time offsets. ```python #!/usr/bin/env python3 import sys import os sys.path.insert(0, os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "lib" )) from lottie.utils import script from lottie import objects from lottie import NVector, Color an = objects.Animation(80) precomp = objects.Precomp("myid", an) # Define stuff in the precomposition (a circle moving left to right) layer = objects.ShapeLayer() precomp.add_layer(layer) layer.out_point = 60 circle = layer.add_shape(objects.Ellipse()) circle.size.value = NVector(100, 100) circle.position.add_keyframe(0, NVector(-50, 50)) circle.position.add_keyframe(60, NVector(512+50, 50)) fill = layer.add_shape(objects.Fill()) fill.color.add_keyframe(0, Color(1, 1, 0)) fill.color.add_keyframe(60, Color(1, 0, 0)) # plays the precomp as it is pcl0 = an.add_layer(objects.PreCompLayer("myid")) # plays the precomp, offset in time by 20 frames and in space by 100 pixels pcl1 = an.add_layer(objects.PreCompLayer("myid")) pcl1.start_time = 20 pcl1.transform.position.value = NVector(0, 100) # playes the composition, but starts it with negative time, so it's farther ahead pcl2 = an.add_layer(objects.PreCompLayer("myid")) pcl2.start_time = -20 pcl2.transform.position.value = NVector(0, 200) # another instance on the same position as the one before # but with a different time offset, to make the animation loop pcl3 = an.add_layer(objects.PreCompLayer("myid")) pcl3.start_time = 60 pcl3.transform.position.value = NVector(0, 200) # Uses time remapping to have more fine tuning on the animation # (goes forward for 40 frames, than backwards) pcl4 = an.add_layer(objects.PreCompLayer("myid")) pcl4.transform.position.value = NVector(0, 300) pcl4.time_remapping = objects.Value() pcl4.time_remapping.add_keyframe(0, 0.1) pcl4.time_remapping.add_keyframe(40, 0.5) ``` -------------------------------- ### Install from Git Source: https://mattbas.gitlab.io/python-lottie/index.html Install the lottie package directly from its GitLab repository. ```bash pip install git+https://gitlab.com/mattbas/python-lottie.git@master ``` -------------------------------- ### Matte Example Source: https://mattbas.gitlab.io/python-lottie/matte_8py-example.html This script demonstrates how to apply a matte effect to a layer using python-lottie. It parses an SVG file, inserts a shape layer, adds a rectangle and a gradient fill, and then applies a Luma matte mode to the last layer. ```python #!/usr/bin/env python3 import sys import os sys.path.insert(0, os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "lib" )) from lottie.utils import script from lottie import objects from lottie.parsers.svg import parse_svg_file from lottie import Point, Color an = parse_svg_file(os.path.join( os.path.dirname(os.path.abspath(__file__)), "blep.svg" )) layer = an.insert_layer(0, objects.ShapeLayer()) r = layer.add_shape(objects.Rect()) r.position.value = Point(256, 256) r.size.value = Point(512, 512) gf = layer.add_shape(objects.GradientFill([(0, Color(1, 1, 1)), (1, Color(0, 0, 0))])) gf.start_point.value = Point(256, 256) gf.end_point.value = Point(256, 64) an.layers[-1].matte_mode = objects.MatteMode.Luma script.script_main(an) ``` -------------------------------- ### Gradient Fill Example Source: https://mattbas.gitlab.io/python-lottie/gradients_8py-example.html This snippet shows how to create a gradient fill for a shape, setting its start and end points, and defining color stops. ```python circle = g3.add_shape(objects.Ellipse()) circle.size.value = Point(100, 100) circle.position.value = Point(128, 356) fill = g3.add_shape(objects.GradientFill()) fill.start_point.value = Point(100, 0) fill.end_point.value = Point(200, 0) fill.colors.set_stops([(0, NVector(1, 0, 0, 1)), (0.5, NVector(1, .5, 0, 1)), (1, NVector(1, 1, 0, 0))]) ``` -------------------------------- ### OffsetKeyframe start property getter Source: https://mattbas.gitlab.io/python-lottie/properties_8py_source.html Gets the start value of the OffsetKeyframe. ```python @property def start(self): return self.valuevalue ``` -------------------------------- ### Installation Source: https://mattbas.gitlab.io/python-lottie/index.html Installs the python-lottie package using pip. ```bash pip install lottie ``` -------------------------------- ### Time Remapping Example Source: https://mattbas.gitlab.io/python-lottie/precomp_8py-example.html This snippet shows how to add a precomposition layer and apply time remapping with keyframes to control its playback speed and timing. ```python 58pcl4.time_remapping.add_keyframe(80, 0.1) 60# Same effect as pcl2+pcl3 but using a single layer and time remapping 61pcl5 = an.add_layer(objects.PreCompLayer("myid")) 62pcl5.transform.position.value = NVector(0, 400) 63pcl5.time_remapping = objects.Value() 64pcl5.time_remapping.add_keyframe(0, 0.333) 65pcl5.time_remapping.add_keyframe(59, 1.333, objects.easing.Jump()) 66pcl5.time_remapping.add_keyframe(60, 0) 67pcl5.time_remapping.add_keyframe(80, 0.333) ``` -------------------------------- ### Install all optional requirements with pip Source: https://mattbas.gitlab.io/python-lottie/index.html Installs all available optional requirements for the lottie package. ```bash pip install lottie[all] ``` -------------------------------- ### Example Usage of TransformStip and Strip Source: https://mattbas.gitlab.io/python-lottie/stripper_8py_source.html Example instantiation of TransformStip and Strip classes. ```python heavy_strip = TransformStip(3, {"ind", "ix", "nm", "mn"}) float_strip = Strip(3) ``` -------------------------------- ### Effects Example Source: https://mattbas.gitlab.io/python-lottie/effects_8py-example.html This script demonstrates how to apply various effects like GaussianBlur, Tint, and DropShadow to a Lottie animation layer. It also shows how to animate effect properties over time. ```python #!/usr/bin/env python3 """ @note Effects are not supported by telegram """ import sys import os sys.path.insert(0, os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "lib" )) from lottie.utils import script from lottie import objects from lottie.parsers.svg import parse_svg_file from lottie import Point, Color last_frame = 120 an = parse_svg_file( os.path.join(os.path.dirname(os.path.abspath(__file__)), "blep.svg"), 0, last_frame ) gaussian = objects.effects.GaussianBlurEffect() an.layers[0].effects = [ #objects.effects.TritoneEffect(Color(1, 0, 0), Color(0, 1, 0), Color(0, 0, 1)), #objects.effects.FillEffect(color=Color(1, 0, 0), opacity=0.5) objects.effects.DropShadowEffect(Color(0, 0, 0), 128, 135, 10, 7), objects.effects.TintEffect(Color(0, 0, 0), Color(0, 1, 0), 90), gaussian, ] gaussian.sigma.add_keyframe(last_frame/2, 0) gaussian.sigma.add_keyframe(last_frame*3/4, 25) gaussian.sigma.add_keyframe(last_frame, 0) script.script_main(an) ``` -------------------------------- ### Inverse Kinematics (IK) Example Source: https://mattbas.gitlab.io/python-lottie/ik_8py-example.html This script demonstrates the creation and manipulation of IK chains and an octopus IK structure. It sets up two basic ellipses that move in circular paths and then defines a chain of joints and an octopus structure with multiple chains, showing how to add joints and create IK objects. ```python #!/usr/bin/env python3 import sys import os import math sys.path.insert(0, os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "lib" )) from lottie.utils import script from lottie import objects from lottie.utils import animation as anutils from lottie import Point, Color from lottie.utils import ik an = objects.Animation(180) layer = objects.ShapeLayer() an.add_layer(layer) g = layer.add_shape(objects.Group()) b1 = g.add_shape(objects.Ellipse()) b1.size.value = Point(20, 20) g.add_shape(objects.Fill(Color(1, 1, 0))) g = layer.add_shape(objects.Group()) b2 = g.add_shape(objects.Ellipse()) b2.size.value = Point(20, 20) g.add_shape(objects.Fill(Color(0, 1, 0))) for i in range(an.out_point): t = i / (an.out_point-1) p1 = Point(math.cos(t*math.pi*2)/2+1, math.sin(t*math.pi*2)/2+1) * 256 b1.position.add_keyframe(i, p1) p2 = Point(math.sin(2*t*math.pi*2)/2+1, -math.cos(t*math.pi*2)/2+1) * 256 b2.position.add_keyframe(i, p2) def chain_bezier(chain): b = objects.Bezier() for seg in chain.joints: b.add_point(seg) return b g = layer.add_shape(objects.Group()) s = g.add_shape(objects.Path()) g.add_shape(objects.Stroke(Color(1, 0, 0), 5)) chain = ik.Chain(Point(0, 0)) chain.add_joint(Point(50, 0)) chain.add_joint(Point(150, 0)) chain.add_joint(Point(350, 0)) chain.add_joint(Point(400, 0)) #chain.add_joint(Point(500, 0)) octmaster = ik.Chain(Point(512, 512), True) octmaster.add_joint(Point(450, 450)) octmaster.add_joint(Point(400, 400)) octmaster.add_joint(Point(450, 450)) octmaster.add_joint(Point(512, 512)) oct = ik.Octopus(octmaster) ch1 = oct.add_chain("ch1") ch1.add_joint(Point(412, 512)) ch1.add_joint(Point(312, 512)) ch2 = oct.add_chain("ch2") ch2.add_joint(Point(512, 412)) ch2.add_joint(Point(512, 312)) ``` -------------------------------- ### __init__ Constructor Source: https://mattbas.gitlab.io/python-lottie/classlottie_1_1gui_1_1console_1_1Console.html Constructor documentation for the Console class. ```python lottie.gui.console.Console.__init__ ( self, *a ) ``` -------------------------------- ### Trim Example Source: https://mattbas.gitlab.io/python-lottie/trim_8py-example.html This script demonstrates how to use the Trim object to animate the start and end points of shapes within a group, creating a dynamic visual effect. It sets up an animation with two stars and a path, then applies a trim to control their visibility over time. ```python #!/usr/bin/env python3 import sys import os sys.path.insert(0, os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "lib" )) from lottie.utils import script from lottie import objects from lottie import Point, Color last_frame = 60 an = objects.Animation(last_frame) layer = objects.ShapeLayer() an.add_layer(layer) group = layer.add_shape(objects.Group()) star = objects.Star() star.inner_radius.value = 40 star.outer_radius.value = 100 star.position.value = Point(256, 256) star.name = "big start" group.add_shape(star) star = objects.Star() star.inner_radius.value = 20 star.outer_radius.value = 50 star.position.value = Point(256, 256) star.name = "small start" group.add_shape(star) obj = objects.Path() obj.shape.value.add_point(Point(10, 10)) obj.shape.value.add_point(Point(500, 10)) group.add_shape(obj) trim = layer.add_shape(objects.Trim()) #trim.offset.value = 350 trim.offset.add_keyframe(0, 0) trim.offset.add_keyframe(last_frame, 360) trim.start.value = 0 trim.end.value = 50 #trim.multiple = objects.TrimMultipleShapes.Individually stroke = group.add_shape(objects.Stroke(Color(1, 1, 0), 10)) script.script_main(an) ``` -------------------------------- ### Constructor & Destructor Documentation Source: https://mattbas.gitlab.io/python-lottie/classlottie_1_1objects_1_1shapes_1_1PuckerBloat.html Documentation for the __init__ method, which is reimplemented from the parent class. ```Python lottie.objects.shapes.PuckerBloat.__init__ | ( | | _self_| ) | ---|---|---|---|---| Reimplemented from lottie.objects.shapes.ShapeElement. Definition at line 859 of file shapes.py. ``` -------------------------------- ### Start Point Property Source: https://mattbas.gitlab.io/python-lottie/classlottie_1_1objects_1_1shapes_1_1Gradient.html The Gradient Start Point attribute, defining the starting point of the gradient. ```python start_point Gradient Start Point. Definition at line 554 of file shapes.py. ``` -------------------------------- ### Argument Parser Setup Source: https://mattbas.gitlab.io/python-lottie/utils_2script_8py_source.html This snippet shows how to set up an argument parser for a script, including options for output name, path, formats, verbosity, and version information. It integrates with the 'exporters' module to determine available formats. ```python def _get_parser(caller, basename, path, formats, verbosity): if basename is None: basename = os.path.splitext(os.path.basename(caller.__file__))[0] parser = argparse.ArgumentParser( conflict_handler='resolve' ) parser.add_argument( "--name", "-n", default=basename, help="Output basename", ) parser.add_argument( "--path", default=path, help="Output path", ) parser.add_argument( "--formats", "-f", nargs="+", choices=list(sum((e.extensions for e in exporters), [])), default=formats, help="Formats to render", metavar="format" ) parser.add_argument( "--verbosity", type=int, default=int(verbosity) ) from .. import __version__ parser.add_argument( "--version", "-v", action="version", version="%(prog)s - python-lottie script " + __version__ ) exporters.set_options(parser) return parser ``` -------------------------------- ### Options Source: https://mattbas.gitlab.io/python-lottie/script_lottie_gui.html Command-line options for the lottie_gui.py script. ```bash -h, --help show this help message and exit --version, -v show program's version number and exit ``` -------------------------------- ### Start Export Source: https://mattbas.gitlab.io/python-lottie/import__export_8py_source.html Function to start the export process in a separate thread. ```python def start_export(parent, exporter, animation, file_name, options): thread = ExportThread(parent, exporter, animation, file_name, options) thread.start() return thread ``` -------------------------------- ### gui/__init__.py Source: https://mattbas.gitlab.io/python-lottie/gui_2____init_____8py_source.html The __init__.py file for the gui module, defining exports. ```python from . import import_export, tree_view, timeline_widget, console, search_widget __all__ = [ "import_export", "tree_view", "timeline_widget", "console", "search_widget" ] ``` -------------------------------- ### __init__ Method Source: https://mattbas.gitlab.io/python-lottie/classlottie_1_1parsers_1_1svg_1_1builder_1_1PrecompTime.html Constructor for the PrecompTime class. ```python def __init__(self, pcl: objects.PreCompLayer): pass ``` -------------------------------- ### OffsetKeyframe start property setter Source: https://mattbas.gitlab.io/python-lottie/properties_8py_source.html Sets the start value of the OffsetKeyframe. ```python @start.setter def start(self, v): self.valuevalue = v return v ``` -------------------------------- ### Usage Source: https://mattbas.gitlab.io/python-lottie/script_lottie_from_description.html Command-line usage for the lottie_from_description.py script. ```bash lottie_from_description.py [-h] [--name ] [--path ] [--formats [ ...]] [--verbosity ] [--version] [--pretty] [--frame ] [--tgs-no-sanitize] [--tgs-no-validate] [--svg-animated] [--gif-skip-frames ] [--webp-lossless] [--webp-quality ] [--webp-method ] [--webp-skip-frames ] [--dotlottie-id ] [--dotlottie-append] [--dotlottie-revision ] [--dotlottie-author ] [--dotlottie-speed ] [--dotlottie-theme-color ] [--dotlottie-no-loop] [--dotlottie-no-pack] [--video-format ] ``` -------------------------------- ### Install optional requirements with pip Source: https://mattbas.gitlab.io/python-lottie/index.html Installs the 'GIF' extra requirements, which includes 'cairosvg' and 'pillow'. ```bash pip install lottie[GIF] ``` -------------------------------- ### DatumAnimation Constructor Source: https://mattbas.gitlab.io/python-lottie/charts_8py_source.html Initializes DatumAnimation with datum, index, and animation settings. ```python def __init__(self, datum: Datum, index_in: int, index_out: int, index_count: int, settings: AnimationSettings): self.datum = datum self.index_in = index_in self.index_out = index_out off1 = self.index_in * settings.offset off2 = self.index_out * settings.offset off_max = index_count * settings.offset self.times = AnimationSettings( start=settings.start + off1, end=settings.end - off_max + off2 ) self.times.fade_in = self.times.start + settings.fade_in self.times.fade_out = self.times.end - settings.fade_out self.times.stay = self.times.fade_out ``` -------------------------------- ### GlaxnimateRenderer.__enter__ Source: https://mattbas.gitlab.io/python-lottie/glaxnimate__helpers_8py_source.html Enters the headless environment and sets up the serializer and document. ```python def __enter__(self): self.context.__enter__() self.serializer = glaxnimate.io.registry.serializer_from_slug(self.serializer_slug) self.document = glaxnimate.model.Document("") glaxnimate.io.registry.from_slug("lottie").load(self.document, json.dumps(self.animation.to_dict()).encode("utf8")) return self ``` -------------------------------- ### Get Blender addon paths Source: https://mattbas.gitlab.io/python-lottie/index.html Get available paths for Blender addons using the Blender Python console. ```python import addon_utils; print(addon_utils.paths()) ``` -------------------------------- ### Get Save File Name Source: https://mattbas.gitlab.io/python-lottie/import__export_8py_source.html Function to get the save file name and exporter from the user using a file dialog. ```python def get_save_filename(parent, title, dirname): extensions = reduce(lambda a, b: a | b, (set(gi.exporter.extensions) for gi in gui_exporters)) all_files = "All Supported Files (%s)" % " ".join("*.%s" % ex for ex in extensions) filters = all_files + ";;" + ";;".join(ge.file_filter for ge in gui_exporters) file_name, filter = QtWidgets.QFileDialog.getSaveFileName( parent, title, dirname, filters ) if file_name: if filter == all_files: exporter = gui_exporter_from_filename(file_name) if exporter: return file_name, exporter else: for exporter in gui_exporters: if exporter.file_filter == filter: return file_name, exporter return None, None ``` -------------------------------- ### __init__.py Source: https://mattbas.gitlab.io/python-lottie/parsers_2sif_2____init_____8py_source.html The __init__.py file for the sif parser module. ```python 1from . import builder, importer 2from .importer import parse_sif_file 3from .builder import to_sif 4 5__all__ = ["builder", "importer", "parse_sif_file", "to_sif"] ``` -------------------------------- ### Get Glyph Name Source: https://mattbas.gitlab.io/python-lottie/font_8py_source.html Gets the glyph name for a given codepoint, using the cmap or calculating it. ```python 373 def glyph_name(self, codepoint): 374 if isinstance(codepoint, str): 375 if len(codepoint) != 1: 376 return "" 377 codepoint = ord(codepoint) 378 379 if codepoint in self.cmap: 380 return self.cmap[codepoint] 381 382 return self.calculated_glyph_name(codepoint) ``` -------------------------------- ### Simple Animation Example Source: https://mattbas.gitlab.io/python-lottie/simple_animations_8py-example.html This script demonstrates how to create a basic animation with a moving circle and changing opacity using the python-lottie library. ```python #!/usr/bin/env python3 import sys import os sys.path.insert(0, os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "lib" )) from lottie.utils import script from lottie import objects from lottie import Point, Color an = objects.Animation(59) layer = objects.ShapeLayer() an.add_layer(layer) circle = layer.add_shape(objects.Ellipse()) circle.size.value = Point(100, 100) circle.position.add_keyframe(0, Point(0, 256)) circle.position.add_keyframe(20, Point(256, 256)) circle.position.add_keyframe(40, Point(256, 0)) circle.position.add_keyframe(60, Point(0, 256)) fill = layer.add_shape(objects.Fill(Color(1, 1, 0))) fill.opacity.add_keyframe(0, 100) fill.opacity.add_keyframe(30, 10) fill.opacity.add_keyframe(60, 100) script.script_main(an) ``` -------------------------------- ### __init__ Method Source: https://mattbas.gitlab.io/python-lottie/classlottie_1_1gui_1_1import__export_1_1GuiProgressReporter.html Initializes the GuiProgressReporter instance. ```python lottie.gui.import_export.GuiProgressReporter.__init__ | ( | | _self_| ) | ---|---|---|---|---|--- Definition at line 12 of file import_export.py. ``` -------------------------------- ### Get Best Cmap Source: https://mattbas.gitlab.io/python-lottie/font_8py_source.html Attempts to get the best available character map (cmap) from the font. ```python 370 def getBestCmap(self): 371 return {} ``` -------------------------------- ### Example Classes Source: https://mattbas.gitlab.io/python-lottie/graph_legend.html This example demonstrates various inheritance and usage scenarios for classes, including documented, undocumented, templated, and inherited classes. ```cpp /*! Invisible class because of truncation */ class Invisible { }; /*! Truncated class, inheritance relation is hidden */ class Truncated : public Invisible { }; /* Class not documented with doxygen comments */ class Undocumented { }; /*! Class that is inherited using public inheritance */ class PublicBase : public Truncated { }; /*! A template class */ template class Templ { }; /*! Class that is inherited using protected inheritance */ class ProtectedBase { }; /*! Class that is inherited using private inheritance */ class PrivateBase { }; /*! Class that is used by the Inherited class */ class Used { }; /*! Super class that inherits a number of other classes */ class Inherited : public PublicBase, protected ProtectedBase, private PrivateBase, public Undocumented, public Templ { private: Used *m_usedClass; }; ``` -------------------------------- ### Constructor Source: https://mattbas.gitlab.io/python-lottie/classlottie_1_1objects_1_1layers_1_1SolidColorLayer.html Initializes a SolidColorLayer with optional color, width, and height. ```python lottie.objects.layers.SolidColorLayer.__init__(self, _color_ = Color(), _width_ = 512, _height_ = 512) ``` -------------------------------- ### __init__ Method Source: https://mattbas.gitlab.io/python-lottie/classexpressions_1_1Converter.html Constructor documentation for the Converter class. ```python expressions.Converter.__init__ ( _self_ ) ``` -------------------------------- ### colorize.py Example Source: https://mattbas.gitlab.io/python-lottie/colorize_8py-example.html This script loads an SVG file, finds a specific layer, and animates its color over a number of frames using LCH color space conversion. ```python #!/usr/bin/env python3 import sys import os sys.path.insert(0, os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "lib" )) import math from lottie.utils import script from lottie import objects from lottie.parsers.svg import parse_svg_file from lottie import Color last_frame = 60 an = parse_svg_file(os.path.join( os.path.dirname(os.path.abspath(__file__)), "blep.svg" ), 0, last_frame) layer = an.find("durg") n_frames = 24 for fill in layer.find_all((objects.Fill, objects.Stroke)): if isinstance(fill.color.value, list): import pdb; pdb.set_trace(); pass color = fill.color.value.converted(Color.Mode.LCH_uv) for frame in range(n_frames): off = frame / (n_frames-1) color.hue = (color.hue + math.tau / (n_frames-1)) % math.tau fill.color.add_keyframe(off * last_frame, color.to_rgb()) script.script_main(an) ``` -------------------------------- ### Basic Animation Creation Source: https://mattbas.gitlab.io/python-lottie/ik_8py-example.html This snippet demonstrates the creation of a simple animation with a group, shapes, and keyframes. ```python 75g = layer.add_shape(objects.Group()) 76octshapes = { 77 n: g.add_shape(objects.Path()) 78 for n in oct.chains.keys() 79} 80g.add_shape(objects.Stroke(Color(0, 0, 1), 5)) 83for i in range(an.out_point): 84 t = i / (an.out_point-1) 85 p1 = Point(math.cos(t*math.pi*2)/2+1, math.sin(t*math.pi*2)/2+1) * 256 86 p2 = Point(math.sin(2*t*math.pi*2)/2+1, -math.cos(t*math.pi*2)/2+1) * 256 87 chain.reach(p1) 88 s.shape.add_keyframe(i, chain_bezier(chain)) 89 90 oct.reach({"ch1": p1, "ch2": p2}) 91 for name, ochain in oct.chains.items(): 92 octshapes[name].shape.add_keyframe(i, chain_bezier(ochain)) 93 94script.script_main(an) ``` -------------------------------- ### Easing Function Example Source: https://mattbas.gitlab.io/python-lottie/easing_8py-example.html This snippet shows how to apply easing functions to scale and position transformations, and add shapes with specific colors based on easing function properties. ```python 55 bezgroup.transform.scale.value = Size(100*width, -100*height) 56 bezgroup.transform.position.value = Point(-width/2, width/2) 57 bezgroup.add_shape(objects.Path()).shape.value = bez 58 sc = Color(0, 0, 0) if easings[i][1].length == math.sqrt(3) else Color(1, 1, 1) 59 bezgroup.add_shape(objects.Stroke(sc, 0.1)) ``` -------------------------------- ### __init__ Method Source: https://mattbas.gitlab.io/python-lottie/classlottie_1_1utils_1_1funky__parser_1_1SvgLoader.html Initializes the SvgLoader object. ```Python lottie.utils.funky_parser.SvgLoader.__init__ (self) ``` -------------------------------- ### Easing Animation Example Source: https://mattbas.gitlab.io/python-lottie/easing_8py-example.html This script creates an animation where multiple rectangles move back and forth, each with a different easing function applied to its position. The color of each rectangle corresponds to the easing function used. ```python #!/usr/bin/env python3 import sys import os import math sys.path.insert(0, os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "lib" )) from lottie.utils import script from lottie import objects from lottie.objects import easing from lottie import Point, Color, Size an = objects.Animation(180) layer = objects.ShapeLayer() an.add_layer(layer) easings = [ (easing.Linear(), Color(1, 1, 1)), (easing.Jump(), Color(0, 0, 0)), (easing.EaseOut(1), Color(1, 0, 0)), (easing.EaseOut(1 / 2), Color(1 / 2, 0, 0)), (easing.EaseOut(1 / 3), Color(1 / 3, 0, 0)), (easing.EaseOut(1 / 5), Color(1 / 5, 0, 0)), (easing.EaseOut(1 / 10), Color(1 / 19, 0, 0)), (easing.EaseIn(1), Color(0, 1, 0)), (easing.EaseIn(1 / 2), Color(0, 1 / 2, 0)), (easing.EaseIn(1 / 3), Color(0, 1 / 3, 0)), (easing.EaseIn(1 / 5), Color(0, 1 / 5, 0)), (easing.EaseIn(1 / 10), Color(0, 1 / 10, 0)), (easing.Sigmoid(1), Color(0, 0, 1)), (easing.Sigmoid(1 / 2), Color(0, 0, 1 / 2)), (easing.Sigmoid(1 / 3), Color(0, 0, 1 / 3)), (easing.Sigmoid(1 / 5), Color(0, 0, 1 / 5)), (easing.Sigmoid(1 / 10), Color(0, 0, 1 / 10)), ] height = 512 / len(easings) width = height for i in range(len(easings)): group = layer.add_shape(objects.Group()) rectgroup = group.add_shape(objects.Group()) rect = rectgroup.add_shape(objects.Rect()) rect.size.value = Size(width, height) y = i * height + height / 2 group.transform.position.add_keyframe(0, Point(width / 2, y), easings[i][0]) group.transform.position.add_keyframe(90, Point(512 - width / 2, y), easings[i][0]) group.transform.position.add_keyframe(180, Point(width / 2, y), easings[i][0]) rectgroup.add_shape(objects.Fill(easings[i][1])) bezgroup = group.insert_shape(0, objects.Group()) bez = group.transform.position.keyframes[0].bezier() ``` -------------------------------- ### Text Layer Example Source: https://mattbas.gitlab.io/python-lottie/text_8py-example.html This Python script demonstrates how to create a text layer with python-lottie, including adding keyframes for text content, color, and position. It also highlights that text layers are not supported by Telegram. ```python #!/usr/bin/env python3 """ @note Text layers are not supported by telegram """ import sys import os sys.path.insert(0, os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "lib" )) from lottie.utils import script from lottie import objects from lottie import Color, Point an = objects.Animation(120) an.fonts = objects.text.FontList() an.fonts.append(objects.text.Font("sans", name="sans")) layer = objects.TextLayer() an.add_layer(layer) layer.data.add_keyframe(0, objects.text.TextDocument("Text", 200, Color(1, 0, 0), "sans")) layer.data.add_keyframe(60, objects.text.TextDocument("Here", 200, Color(0, 1, 0), "sans")) layer.transform.position.value = Point(30, 200) script.script_main(an) ``` -------------------------------- ### Value class initialization and keyframe addition Source: https://mattbas.gitlab.io/python-lottie/properties_8py_source.html Demonstrates how to initialize a Value object and add keyframes to it. ```python def __init__(self, value=0): super().__init__(value) def add_keyframe(self, time, value, ease=easing.Linear()): super().add_keyframe(time, NVector(value), ease) ``` -------------------------------- ### __init__() Constructor Source: https://mattbas.gitlab.io/python-lottie/classlottie_1_1parsers_1_1sif_1_1ast__impl_1_1base_1_1SifAnimated.html Documentation for the __init__ constructor of SifAnimated. ```python lottie.parsers.sif.ast_impl.base.SifAnimated.__init__ | ( | | _self_| ) Definition at line 97 of file base.py. ``` -------------------------------- ### _get_id Source: https://mattbas.gitlab.io/python-lottie/classlottie_1_1parsers_1_1svg_1_1importer_1_1SvgParser-members.html Gets the ID of an element. ```python def _get_id(self, element): ``` -------------------------------- ### _get_dpi Source: https://mattbas.gitlab.io/python-lottie/classlottie_1_1parsers_1_1svg_1_1importer_1_1SvgParser-members.html Gets the DPI of the SVG. ```python def _get_dpi(self, svg): ``` -------------------------------- ### GlaxnimateRenderer.__init__ Source: https://mattbas.gitlab.io/python-lottie/glaxnimate__helpers_8py_source.html Initializes the GlaxnimateRenderer with animation, serializer slug, and DPI. ```python def __init__(self, animation, serializer_slug, dpi): self.context = glaxnimate.environment.Headless() self.serializer_slug = serializer_slug self.serializer = None self.document = None self.animation = animation # TODO dpi ``` -------------------------------- ### ObjectRegistry.get_object Method Source: https://mattbas.gitlab.io/python-lottie/classlottie_1_1parsers_1_1sif_1_1sif_1_1core_1_1ObjectRegistry.html Retrieves an object by its GUID. ```python def get_object(self, guid): pass ``` -------------------------------- ### __init__.py Source: https://mattbas.gitlab.io/python-lottie/parsers_2____init_____8py_source.html The __init__.py file for the parsers directory, which imports submodules like svg, tgs, and optionally sif. ```python from . import svg, tgs __all__ = ["svg", "tgs"] try: from . import sif __all__ += ["sif"] except ImportError: pass ``` -------------------------------- ### Basic Shapes Example Source: https://mattbas.gitlab.io/python-lottie/groups_8py-example.html This script demonstrates how to create and add basic shapes like circles, stars, and rectangles to an animation using the python-lottie library. It also shows how to set their properties such as size, position, fill color, and stroke. ```python #!/usr/bin/env python3 import sys import os sys.path.insert(0, os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "lib" )) from lottie.utils import script from lottie import objects from lottie import Point, Color an = objects.Animation(59) layer = objects.ShapeLayer() an.add_layer(layer) g1 = layer.add_shape(objects.Group()) circle = g1.add_shape(objects.Ellipse()) circle.size.value = Point(100, 100) circle.position.value = Point(200, 100) g1.add_shape(objects.Fill(Color(1, 0, 0))) g1.add_shape(objects.Stroke(Color(0, 0, 0), 5)) g2 = layer.add_shape(objects.Group()) star = g2.add_shape(objects.Star()) star.inner_radius.value = 20 star.outer_radius.value = 50 star.position.value = Point(300, 100) g2.add_shape(objects.Fill(Color(0, 1, 0))) g2.add_shape(objects.Stroke(Color(0, 0, 0), 5)) g3 = layer.add_shape(objects.Group()) rect = g3.add_shape(objects.Rect()) rect.size.value = Point(100, 100) rect.position.value = Point(100, 100) g3.add_shape(objects.Fill(Color(0, 0, 1))) g3.add_shape(objects.Stroke(Color(1, 1, 1), 5)) script.script_main(an) ``` -------------------------------- ### __init__ Method Source: https://mattbas.gitlab.io/python-lottie/classconverter_1_1PropertyPolicyPrepared.html Constructor for the PropertyPolicyPrepared class. ```python def __init__(self, values): pass ``` -------------------------------- ### TextGrouping.default Source: https://mattbas.gitlab.io/python-lottie/text_8py_source.html Class method to get the default TextGrouping. ```python default(cls) ``` -------------------------------- ### nsvar Method Source: https://mattbas.gitlab.io/python-lottie/classlottie_1_1parsers_1_1baseporter_1_1ExtraOption.html Gets a namespace variable. ```python def nsvar(self, slug): pass ``` -------------------------------- ### ObjectRegistry.guid Class Method Source: https://mattbas.gitlab.io/python-lottie/classlottie_1_1parsers_1_1sif_1_1sif_1_1core_1_1ObjectRegistry.html Returns a GUID for the class. ```python @classmethod def guid(cls): pass ``` -------------------------------- ### follow_path example Source: https://mattbas.gitlab.io/python-lottie/follow_path_8py-example.html This script demonstrates how to use the `follow_path` utility to animate objects along a defined path. It sets up an animation with several shapes (an ellipse and rectangles) and animates their positions and rotations along a Bezier curve. ```python #!/usr/bin/env python3 import sys import os sys.path.insert(0, os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "lib" )) from lottie.utils import script from lottie import objects from lottie.utils.animation import follow_path from lottie import Point, Color an = objects.Animation(180) layer = objects.ShapeLayer() an.add_layer(layer) group = layer.add_shape(objects.Group()) ball = group.add_shape(objects.Ellipse()) ball.size.value = Point(10, 10) r1 = group.add_shape(objects.Rect()) r1.size.value = Point(50, 10) r2 = group.add_shape(objects.Group()) r2.add_shape(objects.Rect()).size.value = Point(50, 10) r2 = r2.transform group.add_shape(objects.Fill(Color(0, 1, 0))) group = layer.add_shape(objects.Group()) bez = group.add_shape(objects.Path()) bez.shape.value.add_point(Point(256, 128), Point(0, 0), Point(64, 64)) bez.shape.value.add_point(Point(256, 256), Point(-64, -64), Point(-64, 64)) bez.shape.value.add_point(Point(256, 256+120), Point(0, 0), Point(0, 0)) group.add_shape(objects.Stroke(Color(1, 0, 0), 10)) follow_path(ball.position, bez.shape.value, 0, 90, 30, False, Point(0, 0)) follow_path(ball.position, bez.shape.value, 90, 180, 30, True, Point(0, 0)) follow_path(r1.position, bez.shape.value, 0, 90, 30, False, Point(150, 0)) follow_path(r1.position, bez.shape.value, 90, 180, 30, True, Point(150, 0)) follow_path(r2.position, bez.shape.value, 0, 90, 30, False, Point(-150, 0), 0, r2.rotation, 90) follow_path(r2.position, bez.shape.value, 90, 180, 30, True, Point(-150, 0), 0, r2.rotation, 90) script.script_main(an) ``` -------------------------------- ### EnvelopeDeformation time_start Source: https://mattbas.gitlab.io/python-lottie/classlottie_1_1utils_1_1animation_1_1EnvelopeDeformation.html Returns the time at which the animation shall start. ```python time_start(self) ``` -------------------------------- ### __init__ Method Source: https://mattbas.gitlab.io/python-lottie/classlottie_1_1gui_1_1import__export_1_1GuiBasePorter.html Documentation for the __init__ method of the GuiBasePorter class. ```Python def __init__(self, porter): """Initialize GuiBasePorter. Args: porter: The porter object to use. """ self._porter = porter self.file_filter = "" self.widgets = [] self._dialog = None ```