File indexing completed on 2025-01-19 03:59:52

0001 import math
0002 from .base import LottieObject, LottieProp, PseudoList, PseudoBool
0003 
0004 
0005 ## @ingroup Lottie
0006 class KeyframeBezierHandle(LottieObject):
0007     """!
0008     Bezier handle for keyframe interpolation
0009     """
0010     _props = [
0011         LottieProp("x", "x", list=PseudoList),
0012         LottieProp("y", "y", list=PseudoList),
0013     ]
0014 
0015     def __init__(self, x=0, y=0):
0016         ## x position of the handle.
0017         ## This represents the change in time of the keyframe
0018         self.x = x
0019         ## y position of the handle.
0020         ## This represents the change in value of the keyframe
0021         self.y = y
0022 
0023 
0024 class Linear:
0025     """!
0026     Linear easing, the value will change from start to end in a straight line
0027     """
0028     def __call__(self, keyframe):
0029         keyframe.out_value = KeyframeBezierHandle(
0030             0,
0031             0
0032         )
0033         keyframe.in_value = KeyframeBezierHandle(
0034             1,
0035             1
0036         )
0037 
0038 
0039 class EaseIn:
0040     """!
0041     The value lingers near the start before accelerating towards the end
0042     """
0043     def __init__(self, delay=1/3):
0044         self.delay = delay
0045 
0046     def __call__(self, keyframe):
0047         keyframe.out_value = KeyframeBezierHandle(
0048             self.delay,
0049             0
0050         )
0051         keyframe.in_value = KeyframeBezierHandle(
0052             1,
0053             1
0054         )
0055 
0056 
0057 class EaseOut:
0058     """!
0059     The value starts fast before decelerating towards the end
0060     """
0061     def __init__(self, delay=1/3):
0062         self.delay = delay
0063 
0064     def __call__(self, keyframe):
0065         keyframe.out_value = KeyframeBezierHandle(
0066             0,
0067             0
0068         )
0069         keyframe.in_value = KeyframeBezierHandle(
0070             1-self.delay,
0071             1
0072         )
0073 
0074 
0075 class Jump:
0076     """!
0077     Jumps to the end value at the end of the keyframe
0078     """
0079     def __call__(self, keyframe):
0080         keyframe.jump = True
0081 
0082 
0083 class Sigmoid:
0084     """!
0085     Combines the effects of EaseIn and EaseOut
0086     """
0087     def __init__(self, delay=1/3):
0088         self.delay = delay
0089 
0090     def __call__(self, keyframe):
0091         keyframe.out_value = KeyframeBezierHandle(
0092             self.delay,
0093             0
0094         )
0095         keyframe.in_value = KeyframeBezierHandle(
0096             1 - self.delay,
0097             1
0098         )
0099 
0100 
0101 class Split:
0102     """
0103     Uses different easing methods for in/out
0104     """
0105 
0106     def __init__(self, out_ease, in_ease):
0107         self.out_ease = out_ease
0108         self.in_ease = in_ease
0109 
0110     def __call__(self, keyframe):
0111         self.out_ease(keyframe)
0112         t = keyframe.out_value
0113         self.in_ease(keyframe)
0114         keyframe.out_value = t