2 from .base
import LottieObject, LottieProp, LottieEnum, NVector
3 from .properties
import Value, MultiDimensional, GradientColors, ShapeProperty, Bezier, ColorValue, PositionValue
4 from ..utils.color
import Color
5 from .helpers
import Transform, VisualObject, BlendMode
12 def __init__(self, x1=None, y1=None, x2=None, y2=None):
20 Expands the box to include the point at x, y
23 if self.
x1x1
is None or self.
x1x1 > x:
25 if self.
x2x2
is None or self.
x2x2 < x:
28 if self.
y1y1
is None or self.
y1y1 > y:
30 if self.
y2y2
is None or self.
y2y2 < y:
35 Expands the bounding box to include another bounding box
37 self.
includeinclude(other.x1, other.y1)
38 self.
includeinclude(other.x2, other.y2)
42 Center point of the bounding box
44 return NVector((self.
x1x1 + self.
x2x2) / 2, (self.
y1y1 + self.
y2y2) / 2)
48 Whether the box is default-initialized
50 return self.
x1x1
is None or self.
y2y2
is None
53 return "<BoundingBox [%s, %s] - [%s, %s]>" % (self.
x1x1, self.
y1y1, self.
x2x2, self.
y2y2)
59 return self.
x2x2 - self.
x1x1
65 return self.
y2y2 - self.
y1y1
74 Base class for all elements of ShapeLayer and Group
79 LottieProp(
"property_index",
"cix", int,
False),
80 LottieProp(
"blend_mode",
"bm", BlendMode,
False),
84 _shape_classses =
None
97 Bounding box of the shape element at the given time
102 def _load_get_class(cls, lottiedict):
103 if not ShapeElement._shape_classses:
104 ShapeElement._shape_classses = {}
105 ShapeElement._load_sub(ShapeElement._shape_classses)
106 return ShapeElement._shape_classses[lottiedict[
"ty"]]
109 def _load_sub(cls, dict):
110 for sc
in cls.__subclasses__():
111 if sc.type
and sc.type
not in dict:
134 LottieProp(
"direction",
"d", ShapeDirection,
False),
138 ShapeElement.__init__(self)
144 Returns a Path corresponding to this Shape
146 raise NotImplementedError()
152 A simple rectangle shape
155 LottieProp(
"position",
"p", PositionValue,
False),
156 LottieProp(
"size",
"s", MultiDimensional,
False),
162 def __init__(self, pos=None, size=None, rounded=0):
172 pos = self.
positionposition.get_value(time)
173 sz = self.
sizesize.get_value(time)
184 Returns a Shape corresponding to this rect
189 kft |= set(kf.time
for kf
in self.
positionposition.keyframes)
190 if self.
sizesize.animated:
191 kft |= set(kf.time
for kf
in self.
sizesize.keyframes)
192 if self.
roundedrounded.animated:
193 kft |= set(kf.time
for kf
in self.
roundedrounded.keyframes)
195 shape.shape.value = self.
_bezier_t_bezier_t(0)
197 for time
in sorted(kft):
198 shape.shape.add_keyframe(time, self.
_bezier_t_bezier_t(time))
201 def _bezier_t(self, time):
204 rounded = self.
roundedrounded.get_value(time)
210 if not self.
roundedrounded.animated
and rounded == 0:
220 bezier.add_point(tl+vd, outp=-vh)
221 bezier.add_point(tl+hd, -hh)
222 bezier.add_point(tr-hd, outp=hh)
223 bezier.add_point(tr+vd, -vh)
224 bezier.add_point(br-vd, outp=vh)
225 bezier.add_point(br-hd, hh)
226 bezier.add_point(bl+hd, outp=-hh)
227 bezier.add_point(bl-vd, vh)
245 LottieProp(
"position",
"p", PositionValue,
False),
246 LottieProp(
"inner_radius",
"ir", Value,
False),
247 LottieProp(
"inner_roundness",
"is", Value,
False),
248 LottieProp(
"outer_radius",
"or", Value,
False),
249 LottieProp(
"outer_roundness",
"os", Value,
False),
252 LottieProp(
"star_type",
"sy", StarType,
False),
277 pos = self.
positionposition.get_value(time)
289 Returns a Shape corresponding to this star
294 kft |= set(kf.time
for kf
in self.
positionposition.keyframes)
296 kft |= set(kf.time
for kf
in self.
inner_radiusinner_radius.keyframes)
298 kft |= set(kf.time
for kf
in self.
inner_roundnessinner_roundness.keyframes)
299 if self.
pointspoints.animated:
300 kft |= set(kf.time
for kf
in self.
pointspoints.keyframes)
302 kft |= set(kf.time
for kf
in self.
rotationrotation.keyframes)
305 shape.shape.value = self.
_bezier_t_bezier_t(0)
307 for time
in sorted(kft):
308 shape.shape.add_keyframe(time, self.
_bezier_t_bezier_t(time))
311 def _bezier_t(self, time):
313 pos = self.
positionposition.get_value(time)
316 rot = -(self.
rotationrotation.get_value(time)) * math.pi / 180 + math.pi
317 p = self.
pointspoints.get_value(time)
320 for i
in range(
int(p)):
321 main_angle = rot + i * halfd * 2
322 dx = r2 * math.sin(main_angle)
323 dy = r2 * math.cos(main_angle)
324 bezier.add_point(
NVector(pos.x + dx, pos.y + dy))
326 if self.
star_typestar_type == StarType.Star:
327 dx = r1 * math.sin(main_angle+halfd)
328 dy = r1 * math.cos(main_angle+halfd)
329 bezier.add_point(
NVector(pos.x + dx, pos.y + dy))
341 LottieProp(
"position",
"p", MultiDimensional,
False),
342 LottieProp(
"size",
"s", MultiDimensional,
False),
355 pos = self.
positionposition.get_value(time)
356 sz = self.
sizesize.get_value(time)
367 Returns a Shape corresponding to this ellipse
372 kft |= set(kf.time
for kf
in self.
positionposition.keyframes)
373 if self.
sizesize.animated:
374 kft |= set(kf.time
for kf
in self.
sizesize.keyframes)
376 shape.shape.value = self.
_bezier_t_bezier_t(0)
378 for time
in sorted(kft):
379 shape.shape.add_keyframe(time, self.
_bezier_t_bezier_t(time))
382 def _bezier_t(self, time):
383 from ..utils.ellipse
import Ellipse
as EllipseConverter
386 position = self.
positionposition.get_value(time)
387 radii = self.
sizesize.get_value(time) / 2
389 el = EllipseConverter(position, radii, 0)
390 points = el.to_bezier(0, math.pi*2)
391 for point
in points[1:]:
392 bezier.add_point(point.vertex, point.in_tangent, point.out_tangent)
401 Animatable Bezier curve
404 LottieProp(
"shape",
"ks", ShapeProperty,
False),
418 pos = self.
shapeshape.get_value(time)
421 for v, i, o
in zip(pos.vertices, pos.in_tangents, pos.out_tangents):
435 ShapeElement that can contain other shapes
436 @note Shapes inside the same group will create "holes" in other shapes
439 LottieProp(
"number_of_properties",
"np", float,
False),
440 LottieProp(
"shapes",
"it", ShapeElement,
True),
446 ShapeElement.__init__(self)
454 return self.
shapesshapes[-1]
458 for v
in self.
shapesshapes:
459 bb.expand(v.bounding_box(time))
462 mat = self.
transformtransform.to_matrix(time)
464 mat.apply(
NVector(bb.x1, bb.y1)),
465 mat.apply(
NVector(bb.x1, bb.y2)),
466 mat.apply(
NVector(bb.x2, bb.y2)),
467 mat.apply(
NVector(bb.x2, bb.y1)),
469 x1 = min(p.x
for p
in points)
470 x2 = max(p.x
for p
in points)
471 y1 = min(p.y
for p
in points)
472 y2 = max(p.y
for p
in points)
477 self.
shapesshapes.insert(-1, shape)
481 self.
shapesshapes.insert(index, shape)
486 object = ShapeElement.load(lottiedict)
490 for obj
in object.shapes:
491 if isinstance(obj, TransformShape):
497 object.shapes = shapes
498 object.shapes.append(transform)
516 LottieProp(
"fill_rule",
"r", FillRule,
False),
522 ShapeElement.__init__(self)
540 LottieProp(
"start_point",
"s", MultiDimensional,
False),
541 LottieProp(
"end_point",
"e", MultiDimensional,
False),
542 LottieProp(
"gradient_type",
"t", GradientType,
False),
543 LottieProp(
"highlight_length",
"h", Value,
False),
544 LottieProp(
"highlight_angle",
"a", Value,
False),
545 LottieProp(
"colors",
"g", GradientColors,
False),
572 LottieProp(
"fill_rule",
"r", FillRule,
False),
578 ShapeElement.__init__(self)
579 Gradient.__init__(self, colors)
610 LottieProp(
"type",
"n", StrokeDashType,
False),
614 def __init__(self, length=0, type=StrokeDashType.Dash):
628 LottieProp(
"line_join",
"lj", LineJoin,
False),
629 LottieProp(
"miter_limit",
"ml", float,
False),
656 LottieProp(
"color",
"c", MultiDimensional,
False),
662 ShapeElement.__init__(self)
663 BaseStroke.__init__(self, width)
677 ShapeElement.__init__(self)
678 BaseStroke.__init__(self, stroke_width)
679 Gradient.__init__(self)
694 ShapeElement.__init__(self)
695 Transform.__init__(self)
708 LottieProp(
"start_opacity",
"so", Value,
False),
709 LottieProp(
"end_opacity",
"eo", Value,
False),
713 Transform.__init__(self)
724 class TrimMultipleShapes(LottieEnum):
733 Trims shapes into a segment
739 LottieProp(
"multiple",
"m", TrimMultipleShapes,
False),
745 ShapeElement.__init__(self)
759 Duplicates previous shapes in a group
764 LottieProp(
"composite",
"m", Composite,
False),
765 LottieProp(
"transform",
"tr", RepeaterTransform,
False),
771 Modifier.__init__(self)
786 Rounds corners of other shapes
795 Modifier.__init__(self)
811 ShapeElement.__init__(self)
821 LottieProp(
"center",
"c", MultiDimensional,
False),
827 ShapeElement.__init__(self)
835 Interpolates the shape with its center point and bezier tangents with the opposite direction
844 ShapeElement.__init__(self)
852 Changes the edges of affected shapes into a series of peaks and valleys of uniform size
878 Interpolates the shape with its center point and bezier tangents with the opposite direction
883 LottieProp(
"line_join",
"lj", LineJoin,
False),
884 LottieProp(
"miter_limit",
"ml", Value,
False),
def clone(self)
Returns a copy of the object.
Base class for enum-like types in the Lottie JSON structure.
Base class for mapping Python classes into Lottie JSON objects.
def clone(self)
Returns a copy of the object.
Lottie <-> Python property mapper.
An animatable property that holds a Color.
Represents colors and offsets in a gradient.
An animatable property that holds a NVector.
An animatable property that holds a Bezier.
An animatable property that holds a float.
line_join
Stroke Line Join.
miter_limit
Stroke Miter Limit.
def __init__(self, width=1)
def isnull(self)
Whether the box is default-initialized.
def center(self)
Center point of the bounding box.
def expand(self, other)
Expands the bounding box to include another bounding box.
def include(self, x, y)
Expands the box to include the point at x, y.
def __init__(self, x1=None, y1=None, x2=None, y2=None)
def __init__(self, position=None, size=None)
def to_bezier(self)
Returns a Shape corresponding to this ellipse.
def bounding_box(self, time=0)
Bounding box of the shape element at the given time.
def _bezier_t(self, time)
position
Ellipse's position.
def __init__(self, color=None)
def __init__(self, colors=[])
def __init__(self, stroke_width=1)
def bounding_box(self, time=0)
Bounding box of the shape element at the given time.
highlight_angle
Highlight Angle.
highlight_length
Gradient Highlight Length.
gradient_type
Gradient Type.
start_point
Gradient Start Point.
end_point
Gradient End Point.
def __init__(self, colors=[])
ShapeElement that can contain other shapes.
number_of_properties
Group number of properties.
def bounding_box(self, time=0)
Bounding box of the shape element at the given time.
def add_shape(self, shape)
def insert_shape(self, index, shape)
def load(cls, lottiedict)
Loads from a JSON object.
shapes
Group list of items.
Interpolates the shape with its center point and bezier tangents with the opposite direction.
def __init__(self, bezier=None)
def to_bezier(self)
Returns a Path corresponding to this Shape.
def bounding_box(self, time=0)
Bounding box of the shape element at the given time.
A simple rectangle shape.
def _bezier_t(self, time)
rounded
Rect's rounded corners.
def to_bezier(self)
Returns a Shape corresponding to this rect.
def __init__(self, pos=None, size=None, rounded=0)
def bounding_box(self, time=0)
Bounding box of the shape element at the given time.
transform
Transform values for each repeater copy.
def __init__(self, copies=1)
composite
Composite of copies.
def __init__(self, radius=0)
radius
Rounded Corner Radius.
Base class for all elements of ShapeLayer and Group.
property_index
Property index.
def bounding_box(self, time=0)
Bounding box of the shape element at the given time.
direction
After Effect's Direction.
def to_bezier(self)
Returns a Path corresponding to this Shape.
def bounding_box(self, time=0)
Bounding box of the shape element at the given time.
outer_roundness
Star's outer roundness.
inner_radius
Star's inner radius.
def _bezier_t(self, time)
def to_bezier(self)
Returns a Shape corresponding to this star.
points
Star's number of points.
inner_roundness
Star's inner roundness.
outer_radius
Star's outer radius.
def __init__(self, length=0, type=StrokeDashType.Dash)
def __init__(self, color=None, width=1)
start
Start of the segment, as a percentage.
offset
start/end offset, as an angle (0, 360)
end
End of the segment, as a percentage.
Changes the edges of affected shapes into a series of peaks and valleys of uniform size.
size
Distance between peaks and troughs.
roundness
Radius to maked it a smoother curve.