File indexing completed on 2025-01-19 04:00:00
0001 #!/usr/bin/env python3 0002 import sys 0003 import os 0004 import random 0005 import math 0006 0007 sys.path.insert(0, os.path.join( 0008 os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 0009 "lib" 0010 )) 0011 from lottie.utils import script 0012 from lottie import objects 0013 from lottie.objects import easing 0014 from lottie import Point, Color, Size, PolarVector 0015 from lottie.utils import animation as anutils 0016 0017 0018 last_frame = 120 0019 an = objects.Animation(last_frame) 0020 layer = objects.ShapeLayer() 0021 an.insert_layer(0, layer) 0022 0023 color1 = Color(1, 0.98, 0.282) 0024 color2 = Color(1, 0.341, 0.016) 0025 color3 = Color(0.698, 0.114, 0.02) 0026 particle_start = Point(256, 256) 0027 particle_size = Point(20, 20) 0028 particle_end = Point(256, -particle_size.y*2) 0029 start_len_min = 0 0030 start_len_max = 128 0031 opacity_start = 100 0032 opacity_end = 20 0033 0034 0035 def particle(): 0036 g = layer.add_shape(objects.Group()) 0037 b = g.add_shape(objects.Ellipse()) 0038 fill = objects.Fill() 0039 g.add_shape(fill) 0040 t = random.random() 0041 0042 if t < 1/2: 0043 lf = t * 2 0044 fill.color.add_keyframe(0, color1.lerp(color2, lf)) 0045 fill.color.add_keyframe(last_frame*t, color2) 0046 fill.color.add_keyframe((1 - t) * last_frame, color3, easing.Jump()) 0047 fill.color.add_keyframe((1 - t) * last_frame+1, color1) 0048 fill.color.add_keyframe(last_frame, color1.lerp(color2, lf)) 0049 else: 0050 lf = (t-0.5) * 2 0051 tf = (1-lf)/2 0052 fill.color.add_keyframe(0, color2.lerp(color3, lf)) 0053 fill.color.add_keyframe(last_frame*tf, color3, easing.Jump()) 0054 fill.color.add_keyframe(last_frame*tf+1, color1) 0055 fill.color.add_keyframe((.5 + tf) * last_frame, color2) 0056 fill.color.add_keyframe(last_frame, color2.lerp(color3, lf)) 0057 0058 fill.opacity.add_keyframe(0, opacity_start + (opacity_end - opacity_start) * t) 0059 fill.opacity.add_keyframe((1 - t) * last_frame, opacity_end) 0060 fill.opacity.add_keyframe((1 - t) * last_frame+1, opacity_start) 0061 fill.opacity.add_keyframe(last_frame, opacity_start + (opacity_end - opacity_start) * t) 0062 0063 bezier = objects.Bezier() 0064 outp = PolarVector(random.uniform(start_len_min, start_len_max), random.random() * math.pi) 0065 inp = Point(0, random.random() * (particle_end.y - particle_start.y) / 3) 0066 bezier.add_point(particle_start, outp=outp) 0067 bezier.add_point(particle_end, outp) 0068 0069 b.size.value = particle_size 0070 anutils.follow_path(b.position, bezier, 0, last_frame, 10, start_t=t) 0071 0072 for i in range(100): 0073 particle() 0074 0075 script.script_main(an) 0076