movis.transform.Transform#

class movis.transform.Transform(position: float | tuple[float, float] | ndarray = (0.0, 0.0), scale: float | tuple[float, float] | ndarray = (1.0, 1.0), rotation: float = 0.0, opacity: float = 1.0, anchor_point: float | tuple[float, float] | ndarray = (0.0, 0.0), origin_point: Direction | str = Direction.CENTER, blending_mode: BlendingMode | str = BlendingMode.NORMAL)[source]#

A class responsible for encapsulating the various transformation attributes for a layer.

It utilizes Attribute class to enforce types and optionally ranges for each attribute.

Args:
position:

A float, tuple of floats, or numpy ndarray representing the position (x, y) of an object. Defaults to (0.0, 0.0).

scale:

A float, tuple of floats, or numpy ndarray representing the scale (x, y) of an object. Defaults to (1.0, 1.0).

rotation:

A float value representing the rotation angle in degrees. Defaults to 0.0.

opacity:

A float value representing the opacity of an object. Must be in the range [0, 1]. Defaults to 1.0.

anchor_point:

A float, tuple of floats, or numpy.ndarray representing the anchor point (x, y) of an object. Defaults to (0.0, 0.0).

origin_point:

An enum value from Direction or a string representing the origin point for transformations. Defaults to Direction.CENTER.

Methods

classmethod from_positions(size: tuple[int, int], top: float | None = None, bottom: float | None = None, left: float | None = None, right: float | None = None, object_fit: str | None = None) Transform[source]#

Allows to create Transform by specifying the position based on the edges (top, bottom, left, right).

The object_fit parameter specifies how the object should scale to fit the canvas or container. If object_fit='contain', the object will scale to fit within the canvas while preserving its aspect ratio. If 'cover', the object will scale to completely cover the canvas, also preserving its aspect ratio.

The method calculates the position and origin point of the object based on the supplied arguments and returns a new Transform object.

Args:
size:

A tuple of two integers representing the width (W) and height (H) of the canvas or container.

top:

Optional float, distance from the top edge of the layer. Default is None.

bottom:

Optional float, distance from the bottom edge of the layer. Default is None.

left:

Optional float, distance from the left edge of the layer. Default is None.

right:

Optional float, distance from the right edge of the layer. Default is None.

object_fit:

Optional string, specifies the scaling behavior. Accepts either 'contain' or 'cover'. Default is None (do nothing).

Returns:

A new Transform object with the specified position, scale, and origin point.

get_current_value(layer_time: float) TransformValue[source]#

Retrieves the current transformation attributes for a given time, encapsulated within a TransformValue.

This includes the anchor point, position, scale, rotation, and opacity, all evaluated at layer_time. The transformation attributes are converted to their corresponding 2D vectors or scalar values as appropriate, for easy use or manipulation.

Args:
layer_time:

A float representing the time for which you want to get the current value of all the transformation attributes.

Returns:

TransformValue that encapsulates the current transformation properties (anchor point, position, scale, rotation, opacity, and origin point) for the given layer_time.

Attributes

attributes