def test_layers(self): an = objects.Animation() an.add_layer(objects.NullLayer()) an.add_layer(objects.ShapeLayer()) an.insert_layer(0, objects.NullLayer()) self.assertDictEqual( an.to_dict(), { "ip": 0, "op": 60, "fr": 60, "w": 512, "h": 512, "ddd": 0, "v": objects.Animation._version, "layers": [{ "ty": 3, "ks": TestTransform._plain_out, "ao": 0, "ddd": 0, "st": 0, "sr": 1, "ind": 2, "ip": 0, "op": 60, "bm": 0, }, { "ty": 3, "ks": TestTransform._plain_out, "ao": 0, "ddd": 0, "st": 0, "sr": 1, "ind": 0, "ip": 0, "op": 60, "bm": 0, }, { "ty": 4, "ks": TestTransform._plain_out, "ao": 0, "bm": 0, "ddd": 0, "st": 0, "sr": 1, "shapes": [], "ind": 1, "ip": 0, "op": 60, }], "assets": [], })
def test_clone_noalias(self): an = objects.Animation() nl = objects.NullLayer() nl.in_point = 10 nl.out_point = 20 an.add_layer(nl) an2 = an.clone() nl.in_point = 14 nl.out_point = 24 an.width = 100 an.height = 200 an.add_layer(objects.NullLayer()) self.assertDictEqual( an2.to_dict(), { "ip": 0, "op": 60, "fr": 60, "w": 512, "h": 512, "ddd": 0, "v": objects.Animation._version, "layers": [ { "ty": 3, "ks": TestTransform._plain_out, "ao": 0, "ddd": 0, "st": 0, "sr": 1, "bm": 0, "ind": 0, "ip": 10, "op": 20, }, ], "assets": [], }) self.assertNotEqual(an2.to_dict(), an.to_dict())
def test_empty(self): lay = objects.NullLayer() self.assertDictEqual( lay.to_dict(), { "ty": 3, "ks": TestTransform._plain_out, "ao": 0, "ddd": 0, "st": 0, "sr": 1, "bm": 0, } )
def test_layers_preserve(self): an = objects.Animation() nl = objects.NullLayer() nl.index = 42 nl.in_point = 10 nl.out_point = 20 an.add_layer(nl) self.assertDictEqual( an.to_dict(), { "ip": 0, "op": 60, "fr": 60, "w": 512, "h": 512, "ddd": 0, "v": objects.Animation._version, "layers": [ { "ty": 3, "ks": TestTransform._plain_out, "ao": 0, "ddd": 0, "st": 0, "sr": 1, "bm": 0, "ind": 42, "ip": 10, "op": 20, }, ], "assets": [], })
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, NVector last_frame = 180 an = objects.Animation(last_frame) base = an.add_layer(objects.NullLayer()) base.transform.anchor_point.value = base.transform.position.value = Point(256, 256) base.transform.rotation.add_keyframe(0, 0) base.transform.rotation.add_keyframe(last_frame, 360) star_layer = objects.ShapeLayer() base.add_child(star_layer) star = star_layer.add_shape(objects.Star()) star.inner_radius.value = 20 star.outer_radius.value = 50 star.position.value = Point(50, 50) star_layer.add_shape(objects.Fill(Color(1, 1, 0))) star_layer.add_shape(objects.Stroke(Color(0, 0, 0), 5)) star_layer.transform.anchor_point = star.position star_layer.transform.position.value = Point(50, 256)
def test_sanitize_lowfr(self): an = objects.Animation() an.add_layer(objects.NullLayer()) an.frame_rate = 23 an.tgs_sanitize() self.assertEqual( an.to_dict(), { "ip": 0, "op": 60, "fr": 30, "w": 512, "h": 512, "ddd": 0, "v": objects.Animation._version, "layers": [ { "ty": 3, "ks": { "a": { "a": 0, "k": [0, 0] }, "p": { "a": 0, "k": [0, 0] }, "s": { "a": 0, "k": [100, 100] }, "r": { "a": 0, "k": 0 }, "o": { "a": 0, "k": 100 }, "sk": { "a": 0, "k": 0 }, "sa": { "a": 0, "k": 0 }, }, "ao": 0, "ddd": 0, "st": 0, "sr": 1, "bm": 0, "ind": 0, "ip": 0, "op": 60, }, ], "assets": [], })
def test_sanitize_anim(self): an = objects.Animation() nl = an.add_layer(objects.NullLayer()) nl.transform.scale.add_keyframe(0, NVector(50, 50)) nl.transform.scale.add_keyframe(60, NVector(200, 200)) nl.transform.scale.keyframes[-1].start = None an.width = 128 an.height = 256 an.frame_rate = 69 an.tgs_sanitize() self.assertEqual( an.to_dict(), { "ip": 0, "op": 60, "fr": 60, "w": 512, "h": 512, "ddd": 0, "v": objects.Animation._version, "layers": [ { "ty": 3, "ks": { "a": { "a": 0, "k": [0, 0] }, "p": { "a": 0, "k": [0, 0] }, "s": { "a": 1, "k": [ { "s": [100, 100], "e": [400, 400], "t": 0, "o": { "x": [0], "y": [0] }, "i": { "x": [1], "y": [1] }, }, { "t": 60, }, ] }, "r": { "a": 0, "k": 0 }, "o": { "a": 0, "k": 100 }, "sk": { "a": 0, "k": 0 }, "sa": { "a": 0, "k": 0 }, }, "ao": 0, "ddd": 0, "st": 0, "sr": 1, "bm": 0, "ind": 0, "ip": 0, "op": 60, }, ], "assets": [], })