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:
AnimationEventA 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:
- 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
- get_partial_sketch()[source]¶
Calculates a partial OpsSet representing the current sketching progress.
- 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:
- 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:
- get_partial_sketch(opsset, progress)[source]¶
Calculate a partial OpsSet representing the sketching progress of an operation set.
- Parameters:
- Returns:
- A new OpsSet containing the operations up to the specified progress point,
with the last operation potentially being partially completed.
- Return type:
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:
AnimationEventA 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:
FadeInAnimationA 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.
- class handanim.animations.visibility.Show(start_time=0.0, duration=0.0, easing_fun=None, data=None)[source]¶
Bases:
AnimationEventInstantly 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.
- class handanim.animations.visibility.Hide(start_time=0.0, duration=0.0, easing_fun=None, data=None)[source]¶
Bases:
AnimationEventInstantly hides a drawable at start_time.
- class handanim.animations.visibility.Swap(source, target, start_time=0.0, duration=0.0, easing_fun=None, data=None)[source]¶
Bases:
AnimationEventAtomically 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)
handanim.animations.easing¶
- handanim.animations.easing.ease_in_out_cubic(t)[source]¶
Cubic ease-in-out: accelerates to midpoint then decelerates smoothly.
- handanim.animations.easing.ease_in_out(t)¶
Cubic ease-in-out: accelerates to midpoint then decelerates smoothly.
- handanim.animations.easing.ease_in_back(t, overshoot=1.70158)[source]¶
Back ease-in: pulls back slightly before accelerating forward.
- 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.
- handanim.animations.easing.ease_in_out_back(t, overshoot=1.70158)[source]¶
Symmetric back ease-in-out with slight pull-back and overshoot.
handanim.animations.translate¶
- class handanim.animations.translate.TranslateToAnimation(start_time=0.0, duration=0.0, easing_fun=None, data=None)[source]¶
Bases:
AnimationEventA 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.
- 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:
TranslateToAnimationA 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:
AnimationEventTranslate an OpsSet by a relative (dx, dy) offset over duration seconds.
handanim.animations.rotate¶
- class handanim.animations.rotate.RotateAnimation(start_time=0.0, duration=0.0, easing_fun=None, data=None)[source]¶
Bases:
AnimationEventAnimates 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:
AnimationEventA 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:
ZoomInAnimationA 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:
AnimationEventInterpolates 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:
AnimationEventAnimates 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), } ))
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:
AnimationEventAnimates 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:
rig (CharacterRig)
- Return type:
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:
AnimationEventBase 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.
- 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:
SceneTransitionFolds 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:
- 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'}¶
- 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:
SceneTransitionCrumples 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:
- VALID_DIRECTIONS = {'bottom_left', 'bottom_right', 'left', 'right', 'top_left', 'top_right'}¶