File indexing completed on 2025-01-19 04:00:00

0001 #!/usr/bin/env python3
0002 import sys
0003 import os
0004 import math
0005 sys.path.insert(0, os.path.join(
0006     os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
0007     "lib"
0008 ))
0009 from lottie.utils import script
0010 from lottie import objects
0011 from lottie.utils import animation as anutils
0012 from lottie import Point, Color
0013 
0014 
0015 an = objects.Animation(60)
0016 
0017 layer = objects.ShapeLayer()
0018 an.add_layer(layer)
0019 
0020 heart = objects.Bezier()
0021 heart.add_point(Point(50, 20), Point(50, -20), Point(-50, -20))
0022 heart.add_smooth_point(Point(0, 50), Point(-5, -10))
0023 heart.add_smooth_point(Point(50, 100), Point(-10, 0))
0024 heart.add_smooth_point(Point(100, 50), Point(-5, 10))
0025 heart.closed = True
0026 
0027 g1 = layer.add_shape(objects.Group())
0028 shape = g1.add_shape(objects.Path())
0029 shape.shape.value = heart
0030 fill = layer.add_shape(objects.Fill(Color(1, 0, 0)))
0031 stroke = layer.add_shape(objects.Stroke(Color(0, 0, 0), 5))
0032 
0033 
0034 
0035 g2 = layer.add_shape(objects.Group())
0036 bb = shape.bounding_box()
0037 shapeb = g2.add_shape(objects.Path())
0038 shapeb.shape.value.add_point(Point(bb.x1, bb.y1))
0039 shapeb.shape.value.add_point(Point(bb.x2, bb.y1))
0040 shapeb.shape.value.add_point(Point(bb.x2, bb.y2))
0041 shapeb.shape.value.add_point(Point(bb.x1, bb.y2))
0042 fill = layer.add_shape(objects.Fill([1, 1, 0]))
0043 
0044 
0045 env = anutils.EnvelopeDeformation(Point(bb.x1, bb.y1), Point(bb.x2, bb.y2))
0046 
0047 env.add_keyframe(
0048     0,
0049     Point(256-128, 256-128),
0050     Point(256+128, 256-128),
0051     Point(256+128, 256+128),
0052     Point(256-128, 256+128),
0053 )
0054 
0055 env.add_keyframe(
0056     30,
0057     Point(256, 256-64),
0058     Point(256, 256-128-64),
0059     Point(256, 256+128+64),
0060     Point(256, 256+64),
0061 )
0062 env.add_keyframe(
0063     60,
0064     Point(256+128, 256-128),
0065     Point(256-128, 256-128),
0066     Point(256-128, 256+128),
0067     Point(256+128, 256+128),
0068 )
0069 
0070 env.animate_bezier(shape.shape)
0071 env.animate_bezier(shapeb.shape)
0072 
0073 
0074 script.script_main(an)
0075