animatable

The base of every animatable object, and the @animated_function decorator.

Animatable is what makes an object part of a Scene’s timeline. It owns the object’s Scene, its id (which keys its rows in the timeline’s shared buffers), its Lifespan, and the attribute machinery that turns mob.color = BLUE into a recorded edit rather than an immediate write. spawn, despawn, clone and add_updater live here.

@animated_function is how a plain function becomes an animation. The wrapper enters a child animation context, records a FunctionApplicationEvent against it, and lets the timeline re-execute the function per frame with interpolated arguments – so the function itself is written once, for a single moment, and Algan produces the motion. Arguments named in animated_args are the ones interpolated; the rest are held fixed.

Note the constraint that follows from the recording model: events must be recorded against a context that is entered and exited, because only __exit__ applies the context’s time rescaling. Anything recording events by hand has to wrap itself in a context of its own.

Classes

Animatable

Anything whose state can change over the course of a video.

Functions

animated_function(function=None, *, animated_args=None, unique_args=())[source]

Decorator that turns a function into an animated function. The animation is created by interpolating all args named in the animated_args dict from the value provided in this dict the value passed as an actual argument when the function is called. Most commonly, animated_args will just be {‘t’: 0}, and the function will be called with t=1.

Parameters:
  • function – The function to be decorated. It MUST accept a Mob as its first argument, and any arguments given in animated_args or unique_args must also be arguments of this function.

  • animated_args – A dictionary with strings as keys and floats as values. The strings are names of arguments which will be animated. The arguments will be animated by linearly interpolating their values from the corresponding value provided in the animated_args dict to the value they have when the function is called.

  • unique_args – A list of strings. This is only for batching, when the function is called with different values for a unique argument, they will be batched as two entirely separate functions. Any arguments named in unique_args MUST only accept string values.

attr_ranges_for_mob(attr_timeline, mob)[source]

One mob’s own rows of an attribute buffer, as a RowRanges.

Shared by the descendant-union walk in Animatable._get_attr_ranges() and by the packed-subtree distribution in _distribute_over_packed_subtree(), which has to know which buffer rows each descendant owns.

prepare_kwargs(self, func, args, kwargs, initial_args, unique_args)[source]

Combine args and kwargs and record the call on this mob’s timeline.