movis.attribute.Attribute#

class movis.attribute.Attribute(init_value: float | tuple[float, ...] | ndarray, value_type: AttributeType, range: tuple[float, float] | None = None, motion: Motion | None = None, functions: Sequence[Callable[[ndarray, float], ndarray]] | None = None)[source]#

Attribute class for animating the specified property.

This class is used for animating layer properties. The dimensionality of the values that each Attribute can handle varies depending on the type of property.

This is specified by setting an appropriate value for value_type using AttributeType Enum. For example, the values will be one-dimensional if value_type is set to AttributeType.SCALAR. If set to AttributeType.COLOR, the values will be three-dimensional. Regardless of value_type, the returned type will always be numpy.ndarray.

Note

Even if it’s scalar, the returned value will be an array like np.array([value]).

Args:
init_value:

The initial value to use. It is used when no animation is set, or when an animation with zero keyframes is set.

value_type:

Specifies the type of value that the Attribute will handle. For more details, see the docs of AttributeType.

range:

Defines the upper and lower limits of the possible values. If set, the returned array’s values are guaranteed to be within this range; values that exceed this range are simply clipped.

motion:

The instance of the motion to use when adding keyframe animations. It can be specified in the constructor or activated later using enable_motion().

functions:

User-defined functions for adding animations, separate from keyframe animations. It can be specified in the constructor or added later using add_function().

Methods

add_function(function: Callable[[ndarray, float], ndarray]) Callable[[ndarray, float], ndarray][source]#

Add a user-defined function for adding animations, separate from keyframe animations.

Args:

function: A function that takes two arguments, value and time and returns an array.

Returns:

The function that was added.

clear_functions() None[source]#

Remove all user-defined functions.

disable_motion() None[source]#

Remove Motion object.

enable_motion() Motion[source]#

Enable Motion object to animate the attribute.

get_values(layer_times: ndarray) ndarray[source]#

Returns an array of values for the specified layer times.

Args:

layer_times: An array of times for which to get the values.

Returns:

An array of values for the specified layer times.

pop_function(index: int) Callable[[ndarray, float], ndarray][source]#

Remove a user-defined function of the specified index.

set(init_value: float | Sequence[float] | ndarray) None[source]#

Set the initial value of the attribute.

Note

This method is equivalent to init_value = value.

Args:

init_value: The value to set.

Examples:
>>> import movis as mv
>>> layer = mv.layer.Rectangle(size=(100, 100), color=(255, 0, 0))
>>> layer.size.set((200, 200))
>>> layer.color.set((0, 255, 0))

Attributes

functions

User-defined functions for adding animations, separate from keyframe animations.

init_value

The initial value of the attribute.

motion

The instance of the motion to use when adding keyframe animations.

range

The upper and lower limits of the possible values.

value_type

The type of value that the attribute handles.