handanim.animations Package

handanim.animations.sketch

class handanim.animations.sketch.SketchAnimation(start_time=0.0, duration=0.0, easing_fun=None, data=None, *, wait_before_fill=None, glowing_dot=None, sound=None, sound_volume=None, sound_style=None)[source]

Bases: AnimationEvent

A class representing a sketch animation event that progressively renders drawing operations.

This animation supports partial rendering of drawing and fill operations with configurable timing and optional glowing dot effects. It allows for smooth, incremental visualization of drawing sequences.

Parameters:
wait_before_fill

Delay in seconds before starting fill animation, capped at half the total duration.

Type:

float

sound

Per-animation override to turn sketch drawing sound on (True) or off (False). When None (default), inherits the scene’s sketch_sound setting.

Type:

bool | None

sound_volume

Optional per-animation volume multiplier (0.0 to 1.0) for the sketch sound.

Type:

float | None

sound_style

Optional per-animation sound style (“chalk” or “pen”).

Type:

str | None

get_partial_sketch()[source]

Calculates a partial OpsSet representing the current sketching progress.

Parameters:
Return type:

OpsSet

apply()

Applies the sketch animation to a given OpsSet at a specific progress point.

set_sound()[source]

Enables, disables, or adjusts the volume/style of the sketch sound for this event.

Parameters:
Return type:

SketchAnimation

set_sound(enabled=True, volume=None, style=None)[source]

Turn sketch sound on or off or adjust its volume/style for this animation event.

Parameters:
Return type:

SketchAnimation

get_partial_sketch(opsset, progress)[source]

Calculate a partial OpsSet representing the sketching progress of an operation set.

Parameters:
  • OpsSet – The full drawn opsset on which to apply partial sketching

  • progress (float) – The progress of sketching, ranging from 0.0 to 1.0.

  • opsset (OpsSet)

Returns:

A new OpsSet containing the operations up to the specified progress point,

with the last operation potentially being partially completed.

Return type:

OpsSet

handanim.animations.fade

class handanim.animations.fade.FadeInAnimation(start_time=0.0, duration=0.0, easing_fun=None, data=None, initial_opacity=0.0)[source]

Bases: AnimationEvent

A class representing a fade-in animation event that gradually increases the opacity of elements.

This animation applies a progressive opacity change from 0 to 1 over a specified duration, creating a smooth fade-in effect for graphical elements.

Parameters:
  • start_time (float, optional) – The time at which the animation begins. Defaults to 0.

  • duration (float, optional) – The total duration of the animation. Defaults to 0.

  • easing_fun (callable, optional) – An optional function to modify the animation’s progress curve. Defaults to None.

  • data (dict, optional) – Additional data associated with the animation. Defaults to None.

  • initial_opacity (float)

class handanim.animations.fade.FadeOutAnimation(start_time=0.0, duration=0.0, easing_fun=None, data=None)[source]

Bases: FadeInAnimation

A class representing a fade-out animation event that gradually decreases the opacity of elements.

This animation applies a progressive opacity change from 1 to 0 over a specified duration, creating a smooth fade-out effect for graphical elements.

Parameters:
  • start_time (float, optional) – The time at which the animation begins. Defaults to 0.

  • duration (float, optional) – The total duration of the animation. Defaults to 0.

  • easing_fun (callable, optional) – An optional function to modify the animation’s progress curve. Defaults to None.

  • data (dict, optional) – Additional data associated with the animation. Defaults to None.

handanim.animations.visibility

handanim.animations.visibility.restore_base_opacity(opsset)[source]

Restore original opacity on an OpsSet whose opacity was scaled by a fade.

Parameters:

opsset (OpsSet)

Return type:

OpsSet

class handanim.animations.visibility.Show(start_time=0.0, duration=0.0, easing_fun=None, data=None)[source]

Bases: AnimationEvent

Instantly makes a drawable visible at start_time, restoring its original opacity.

Useful for placing hooks on screen at frame 0 (Show(0)) or toggling blinks, mouth shapes, and labels back on after Hide or FadeOutAnimation.

Parameters:
class handanim.animations.visibility.Hide(start_time=0.0, duration=0.0, easing_fun=None, data=None)[source]

Bases: AnimationEvent

Instantly hides a drawable at start_time.

Parameters:
class handanim.animations.visibility.Swap(source, target, start_time=0.0, duration=0.0, easing_fun=None, data=None)[source]

Bases: AnimationEvent

Atomically swaps source out and target in at start_time.

If duration == 0.0 (default), performs an instant Hide(start_time) on source and Show(start_time) on target. If duration > 0.0, cross-fades between them.

Usage:

scene.add(Swap(closed_mouth, open_mouth, 1.2))
# or
scene.swap(closed_mouth, open_mouth, 1.2)
Parameters:
handanim.animations.visibility.ShowAnimation

alias of Show

handanim.animations.visibility.HideAnimation

alias of Hide

handanim.animations.visibility.SwapAnimation

alias of Swap

handanim.animations.easing

handanim.animations.easing.linear(t)[source]

Linear identity easing: f(t) = t.

Parameters:

t (float)

Return type:

float

handanim.animations.easing.ease_in_quad(t)[source]

Quadratic ease-in: f(t) = t^2.

Parameters:

t (float)

Return type:

float

handanim.animations.easing.ease_out_quad(t)[source]

Quadratic ease-out: f(t) = 1 - (1 - t)^2.

Parameters:

t (float)

Return type:

float

handanim.animations.easing.ease_in_out_quad(t)[source]

Quadratic ease-in-out.

Parameters:

t (float)

Return type:

float

handanim.animations.easing.ease_in_cubic(t)[source]

Cubic ease-in: f(t) = t^3.

Parameters:

t (float)

Return type:

float

handanim.animations.easing.ease_out_cubic(t)[source]

Cubic ease-out: f(t) = 1 - (1 - t)^3.

Parameters:

t (float)

Return type:

float

handanim.animations.easing.ease_in_out_cubic(t)[source]

Cubic ease-in-out: accelerates to midpoint then decelerates smoothly.

Parameters:

t (float)

Return type:

float

handanim.animations.easing.ease_in_out(t)

Cubic ease-in-out: accelerates to midpoint then decelerates smoothly.

Parameters:

t (float)

Return type:

float

handanim.animations.easing.ease_in_back(t, overshoot=1.70158)[source]

Back ease-in: pulls back slightly before accelerating forward.

Parameters:
Return type:

float

handanim.animations.easing.ease_out_back(t, overshoot=1.9)[source]

Overshoot ‘pop’ ease-out: overshoots 1.0 slightly then settles back to 1.0.

Parameters:
Return type:

float

handanim.animations.easing.ease_in_out_back(t, overshoot=1.70158)[source]

Symmetric back ease-in-out with slight pull-back and overshoot.

Parameters:
Return type:

float

handanim.animations.easing.ease_out_elastic(t)[source]

Elastic spring ease-out.

Parameters:

t (float)

Return type:

float

handanim.animations.easing.ease_out_bounce(t)[source]

Bounce ease-out.

Parameters:

t (float)

Return type:

float

class handanim.animations.easing.PopAnimation(start_time=0.0, duration=0.32, overshoot=1.9, easing_fun=None, data=None)[source]

Bases: ZoomInAnimation

Zoom-in animation with an overshoot ‘pop’ easing (ease_out_back).

Parameters:

handanim.animations.translate

class handanim.animations.translate.TranslateToAnimation(start_time=0.0, duration=0.0, easing_fun=None, data=None)[source]

Bases: AnimationEvent

A class representing a translate to a point animation event.

This animation translates an OpsSet from its current center of gravity to a specified point over the course of the animation’s duration, using an optional easing function.

Parameters:
  • start_time (float, optional) – The start time of the animation. Defaults to 0.

  • duration (float, optional) – The duration of the animation. Defaults to 0.

  • easing_fun (callable, optional) – An optional easing function to modify animation progress. Defaults to None.

  • data (dict, optional) – A dictionary containing animation data, including the target ‘point’. Defaults to None.

_opsset_apply()[source]

Calculates and applies the translation of the OpsSet.

apply()

Applies the translation to the given OpsSet at the specified progress.

class handanim.animations.translate.TranslateFromAnimation(start_time=0, duration=0, easing_fun=None, data=None)[source]

Bases: TranslateToAnimation

A class representing a translate from a point animation event.

This animation translates an OpsSet from a specified point to its current center of gravity over the course of the animation’s duration, using an optional easing function.

Inherits from TranslateToAnimation and reverses the progress to achieve the “from” translation effect.

Parameters:
  • start_time (float, optional) – The start time of the animation. Defaults to 0.

  • duration (float, optional) – The duration of the animation. Defaults to 0.

  • easing_fun (callable, optional) – An optional easing function to modify animation progress. Defaults to None.

  • data (dict, optional) – A dictionary containing animation data, including the starting ‘point’. Defaults to None.

apply()

Applies the translation from the specified point to the OpsSet’s center of gravity.

class handanim.animations.translate.MoveBy(dx=0.0, dy=0.0, start_time=0.0, duration=0.0, easing_fun=None, data=None, *, offset=None)[source]

Bases: AnimationEvent

Translate an OpsSet by a relative (dx, dy) offset over duration seconds.

Parameters:
handanim.animations.translate.TranslateByAnimation

alias of MoveBy

handanim.animations.rotate

class handanim.animations.rotate.RotateAnimation(start_time=0.0, duration=0.0, easing_fun=None, data=None)[source]

Bases: AnimationEvent

Animates a rotation of an OpsSet from 0 to angle degrees over the duration.

The rotation is applied around the center of gravity by default, or around a fixed center point if provided in data.

Parameters:
  • start_time – When the animation begins (seconds).

  • duration – Length of the animation (seconds).

  • easing_fun – Optional easing function.

  • data (dict) – Dict with optional keys: - “angle” (float): Total rotation angle in degrees. Default 360. - “center” (tuple[float, float]): Fixed pivot point. Default: center of gravity.

handanim.animations.zoom

class handanim.animations.zoom.ZoomInAnimation(start_time=0.0, duration=0.0, easing_fun=None, data=None)[source]

Bases: AnimationEvent

A class representing a zoom-in animation event that scales an OpsSet progressively.

This animation scales the operations set from its original size to a larger size based on the provided progress value. It is typically used for creating or expanding visual elements.

Parameters:
  • start_time (int, optional) – The start time of the animation. Defaults to 0.

  • duration (int, optional) – The duration of the animation. Defaults to 0.

  • easing_fun (callable, optional) – An optional easing function to modify the animation progress. Defaults to None.

  • data (Any, optional) – Additional data associated with the animation. Defaults to None.

class handanim.animations.zoom.ZoomOutAnimation(start_time=0.0, duration=0.0, easing_fun=None, data=None)[source]

Bases: ZoomInAnimation

A class representing a zoom-out animation event that scales an OpsSet progressively.

This animation scales the operations set from its current size to a smaller size based on the provided progress value. It is typically used for shrinking or removing visual elements.

Parameters:
  • start_time (int, optional) – The start time of the animation. Defaults to 0.

  • duration (int, optional) – The duration of the animation. Defaults to 0.

  • easing_fun (callable, optional) – An optional easing function to modify the animation progress. Defaults to None.

  • data (Any, optional) – Additional data associated with the animation. Defaults to None.

handanim.animations.color_transition

class handanim.animations.color_transition.ColorTransitionAnimation(start_time=0.0, duration=0.0, easing_fun=None, data=None)[source]

Bases: AnimationEvent

Interpolates every SET_PEN color in an OpsSet from start_color to end_color.

At progress=0 all strokes are rendered with start_color; at progress=1 they use end_color. The fill color (if present) is interpolated identically.

Parameters:
  • start_time – When the animation begins (seconds).

  • duration – Length of the animation (seconds).

  • easing_fun – Optional easing function.

  • data (dict) – Dict with keys: - “start_color” (tuple[float,float,float]): RGB at progress 0. Required. - “end_color” (tuple[float,float,float]): RGB at progress 1. Required.

handanim.animations.camera

class handanim.animations.camera.CameraAnimation(start_time=0.0, duration=0.0, easing_fun=None, data=None)[source]

Bases: AnimationEvent

Animates the Scene viewport (pan and/or zoom) over time.

Instead of touching any drawable’s OpsSet, this animation changes the world ranges that the Viewport maps to the screen — the “camera” moves, not the content.

Parameters:
  • start_time – When the animation begins (seconds).

  • duration – Length of the animation (seconds).

  • easing_fun – Optional easing function applied to progress.

  • data (dict) –

    Dict with optional keys:

    • "from_xrange" (tuple[float, float]): World x range at progress=0. Defaults to wherever the camera currently is.

    • "from_yrange" (tuple[float, float]): World y range at progress=0. Defaults to wherever the camera currently is.

    • "to_xrange" (tuple[float, float]): World x range at progress=1. Defaults to from_xrange (no movement on x).

    • "to_yrange" (tuple[float, float]): World y range at progress=1. Defaults to from_yrange (no movement on y).

Usage:

scene.add_camera(CameraAnimation(
    start_time=5, duration=3,
    data={
        "to_xrange": (400, 800),
        "to_yrange": (200, 600),
    }
))
apply_to_viewport(current, progress)[source]

Return a new Viewport interpolated toward the target world ranges.

Parameters:
  • current (Viewport) – The viewport state immediately before this event (used as the from_* default when not explicitly specified).

  • progress (float) – Animation progress from 0.0 to 1.0.

Returns:

A new Viewport instance with interpolated world ranges.

Return type:

Viewport

handanim.animations.pose

class handanim.animations.pose.PoseAnimation(rig=None, to_pose=None, from_pose=None, start_time=0.0, duration=0.0, keyframes=None, easing_fun=None, data=None)[source]

Bases: AnimationEvent

Animates a CharacterRig between poses by blending joint angles, offsets, scales, and IK targets.

Supports both two-pose transitions (from_pose -> to_pose) and multi-keyframe sequences (keyframes=[(t0, pose0), (t1, pose1), …]).

Parameters:
classmethod from_keyframes(rig, keyframes, easing_fun=None)[source]

Create a PoseAnimation from a sequence of (timestamp, Pose) keyframes.

Parameters:
Return type:

PoseAnimation

get_pose_at_progress(raw_progress)[source]

Compute the blended Pose and scene timestamp at raw_progress in [0, 1].

Parameters:

raw_progress (float)

Return type:

tuple[Pose, float]

apply(opsset, raw_progress)[source]

Public entry point called by Scene. Applies easing (if any) then delegates to _apply(). Do not override in subclasses — implement _apply() instead.

Parameters:
Return type:

OpsSet

handanim.animations.transitions

Scene-level page-turn (paper fold) and paper-crumple transition animations.

class handanim.animations.transitions.SceneTransition(start_time=0.0, duration=1.0, easing_fun=<function ease_in_out_cubic>, data=None)[source]

Bases: AnimationEvent

Base class for scene-level page transitions (PageTurnTransition, PaperCrumpleTransition).

When added to a Scene via scene.add_transition(transition) or scene.add(transition):

  • All world drawables created before transition.start_time belong to the outgoing page and are automatically deactivated at transition.end_time.

  • Any world drawables created at or after transition.start_time belong to the newly revealed page underneath.

  • Camera-invariant scene.overlay drawables (e.g. Captions) remain untouched above the page.

Parameters:
sfx_type: str = 'page_turn'
apply_transition(outgoing_ops, incoming_ops, raw_progress, viewport, background_color=(1.0, 1.0, 1.0))[source]

Compose the outgoing and incoming page OpsSet`s at `raw_progress in [0, 1].

Parameters:
Return type:

OpsSet

class handanim.animations.transitions.PageTurnTransition(start_time=0.0, duration=1.0, direction='right_to_left', bleed_through=0.16, flap_color=None, border_color=(0.32, 0.3, 0.27), shadow_opacity=0.14, easing_fun=<function ease_in_out_cubic>, data=None)[source]

Bases: SceneTransition

Folds and turns the current drawing sheet across the board to reveal the next page.

Supported direction values: - "right_to_left" (default): Lifts the right side of the paper and folds it left. - "left_to_right": Lifts the left side of the paper and folds it right. - "bottom_right" (or "right_corner_to_left_corner"): Peels the bottom-right corner diagonally across to top-left. - "bottom_left" (or "left_corner_to_right_corner"): Peels the bottom-left corner diagonally across to top-right. - "top_right": Peels the top-right corner diagonally across to bottom-left. - "top_left": Peels the top-left corner diagonally across to bottom-right. - "bottom_to_top": Flips the bottom edge of the notepad upward. - "top_to_bottom": Flips the top edge downward.

Parameters:
sfx_type: str = 'page_turn'
VALID_DIRECTIONS = {'bottom_left', 'bottom_right', 'bottom_to_top', 'left_corner_to_right_corner', 'left_to_right', 'right_corner_to_left_corner', 'right_to_left', 'top_left', 'top_right', 'top_to_bottom'}
apply_transition(outgoing_ops, incoming_ops, raw_progress, viewport, background_color=(1.0, 1.0, 1.0))[source]

Compose the outgoing and incoming page OpsSet`s at `raw_progress in [0, 1].

Parameters:
Return type:

OpsSet

class handanim.animations.transitions.PaperCrumpleTransition(start_time=0.0, duration=1.0, direction='right', seed=42, paper_color=None, border_color=(0.32, 0.3, 0.27), easing_fun=<function ease_in_out_cubic>, data=None)[source]

Bases: SceneTransition

Crumples the current sheet of paper into a jagged paper ball and tosses it off to the side.

Supported direction values: - "right" (default): Crumples toward center and tosses off the right edge. - "left": Crumples toward center and tosses off the left edge. - "top_right", "bottom_right", "top_left", "bottom_left"

Parameters:
sfx_type: str = 'crumple'
VALID_DIRECTIONS = {'bottom_left', 'bottom_right', 'left', 'right', 'top_left', 'top_right'}
apply_transition(outgoing_ops, incoming_ops, raw_progress, viewport, background_color=(1.0, 1.0, 1.0))[source]

Compose the outgoing and incoming page OpsSet`s at `raw_progress in [0, 1].

Parameters:
Return type:

OpsSet