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

0001 #!/usr/bin/env python3
0002 import sys
0003 import os
0004 sys.path.insert(0, os.path.join(
0005     os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
0006     "lib"
0007 ))
0008 from lottie.utils import script
0009 from lottie import objects
0010 from lottie import NVector, Color
0011 
0012 
0013 an = objects.Animation(80)
0014 
0015 precomp = objects.Precomp("myid", an)
0016 
0017 # Define stuff in the precomposition (a circle moving left to right)
0018 layer = objects.ShapeLayer()
0019 precomp.add_layer(layer)
0020 layer.out_point = 60
0021 
0022 circle = layer.add_shape(objects.Ellipse())
0023 circle.size.value = NVector(100, 100)
0024 circle.position.add_keyframe(0, NVector(-50, 50))
0025 circle.position.add_keyframe(60, NVector(512+50, 50))
0026 
0027 fill = layer.add_shape(objects.Fill())
0028 fill.color.add_keyframe(0, Color(1, 1, 0))
0029 fill.color.add_keyframe(60, Color(1, 0, 0))
0030 
0031 
0032 # plays the precomp as it is
0033 pcl0 = an.add_layer(objects.PreCompLayer("myid"))
0034 
0035 # plays the precomp, offset in time by 20 frames and in space by 100 pixels
0036 pcl1 = an.add_layer(objects.PreCompLayer("myid"))
0037 pcl1.start_time = 20
0038 pcl1.transform.position.value = NVector(0, 100)
0039 
0040 # playes the composition, but starts it with negative time, so it's farther ahead
0041 pcl2 = an.add_layer(objects.PreCompLayer("myid"))
0042 pcl2.start_time = -20
0043 pcl2.transform.position.value = NVector(0, 200)
0044 
0045 # another instance on the same position as the one before
0046 # but with a different time offset, to make the animation loop
0047 pcl3 = an.add_layer(objects.PreCompLayer("myid"))
0048 pcl3.start_time = 60
0049 pcl3.transform.position.value = NVector(0, 200)
0050 
0051 # Uses time remapping to have more fine tuning on the animation
0052 # (goes forward for 40 frames, than backwards)
0053 pcl4 = an.add_layer(objects.PreCompLayer("myid"))
0054 pcl4.transform.position.value = NVector(0, 300)
0055 pcl4.time_remapping = objects.Value()
0056 pcl4.time_remapping.add_keyframe(0, 0.1)
0057 pcl4.time_remapping.add_keyframe(40, 0.5)
0058 pcl4.time_remapping.add_keyframe(80, 0.1)
0059 
0060 # Same effect as pcl2+pcl3 but using a single layer and time remapping
0061 pcl5 = an.add_layer(objects.PreCompLayer("myid"))
0062 pcl5.transform.position.value = NVector(0, 400)
0063 pcl5.time_remapping = objects.Value()
0064 pcl5.time_remapping.add_keyframe(0, 0.333)
0065 pcl5.time_remapping.add_keyframe(59, 1.333, objects.easing.Jump())
0066 pcl5.time_remapping.add_keyframe(60, 0)
0067 pcl5.time_remapping.add_keyframe(80, 0.333)
0068 
0069 script.script_main(an)
0070