handanim.animations package

Submodules

handanim.animations.fade module

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

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.

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

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.sketch module

class handanim.animations.sketch.SketchAnimation(start_time=0.0, duration=0.0, easing_fun=None, data=None)

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.

wait_before_fill

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

Type:

float

get_partial_sketch()

Calculates a partial OpsSet representing the current sketching progress.

apply()

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

get_partial_sketch(opsset: OpsSet, progress: float) OpsSet

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.

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.translate module

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

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.TranslateToAnimation(start_time=0.0, duration=0.0, easing_fun=None, data=None)

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()

Calculates and applies the translation of the OpsSet.

apply()

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

handanim.animations.zoom module

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

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)

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.

Module contents

class handanim.animations.CameraAnimation(start_time=0.0, duration=0.0, easing_fun=None, data=None)

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 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: Viewport, progress: float) Viewport

Return a new Viewport interpolated toward the target world ranges.

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

  • progress – Animation progress from 0.0 to 1.0.

Returns:

A new Viewport instance with interpolated world ranges.

class handanim.animations.ColorTransitionAnimation(start_time=0.0, duration=0.0, easing_fun=None, data=None)

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 with keys: - “start_color” (tuple[float,float,float]): RGB at progress 0. Required. - “end_color” (tuple[float,float,float]): RGB at progress 1. Required.

class handanim.animations.FadeInAnimation(start_time=0.0, duration=0.0, easing_fun=None, data=None)

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.

class handanim.animations.FadeOutAnimation(start_time=0.0, duration=0.0, easing_fun=None, data=None)

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.

class handanim.animations.RotateAnimation(start_time=0.0, duration=0.0, easing_fun=None, data=None)

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 with optional keys: - “angle” (float): Total rotation angle in degrees. Default 360. - “center” (tuple[float, float]): Fixed pivot point. Default: center of gravity.

class handanim.animations.SketchAnimation(start_time=0.0, duration=0.0, easing_fun=None, data=None)

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.

wait_before_fill

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

Type:

float

get_partial_sketch()

Calculates a partial OpsSet representing the current sketching progress.

apply()

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

get_partial_sketch(opsset: OpsSet, progress: float) OpsSet

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.

Returns:

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

with the last operation potentially being partially completed.

Return type:

OpsSet

class handanim.animations.TranslateFromAnimation(start_time=0, duration=0, easing_fun=None, data=None)

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.TranslateToAnimation(start_time=0.0, duration=0.0, easing_fun=None, data=None)

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()

Calculates and applies the translation of the OpsSet.

apply()

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

class handanim.animations.ZoomInAnimation(start_time=0.0, duration=0.0, easing_fun=None, data=None)

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.ZoomOutAnimation(start_time=0.0, duration=0.0, easing_fun=None, data=None)

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.