handanim.primitives package¶
Submodules¶
handanim.primitives.curves module¶
- class handanim.primitives.curves.Curve(points: List[Tuple[float, float]], *args, **kwargs)¶
Bases:
Drawable
A class representing a curve that can be drawn with a sketchy, hand-drawn style.
Allows creating curves with multiple points, supporting various drawing techniques including single line, quadratic, and more complex multi-point curves with randomization to simulate hand-drawn appearance.
- points¶
List of points defining the curve’s shape.
- Type:
List[np.ndarray]
handanim.primitives.ellipse module¶
- class handanim.primitives.ellipse.Circle(center: tuple[float, float], radius: float, *args, **kwargs)¶
Bases:
Ellipse
A specialized Ellipse where the x and y radii are equal, creating a perfect circle.
- Parameters:
center (tuple[float, float]) – The center coordinates of the circle.
radius (float) – The radius of the circle.
- class handanim.primitives.ellipse.Ellipse(center: Tuple[float, float], width: float, height: float, *args, **kwargs)¶
Bases:
Drawable
A drawable ellipse primitive with sketchy rendering capabilities.
Supports customizable center, width, height, and sketch-style rendering with optional multi-stroke and roughness effects. Allows for generating ellipses with randomized point generation and stroke variations.
- center¶
The center point of the ellipse
- Type:
np.ndarray
- width¶
The width of the ellipse
- Type:
float
- height¶
The height of the ellipse
- Type:
float
- class handanim.primitives.ellipse.GlowDot(center: Tuple[float, float], radius: float = 1, *args, **kwargs)¶
Bases:
Drawable
A drawable glowing dot with customizable center, radius, and opacity scaling.
Renders a dot with multiple overlapping layers of decreasing opacity and increasing radius to create a glowing effect.
- Parameters:
center (Tuple[float, float]) – The center coordinates of the dot.
radius (float, optional) – The base radius of the dot. Defaults to 1.
handanim.primitives.eraser module¶
- class handanim.primitives.eraser.Eraser(objects_to_erase: List[Drawable], drawable_cache: DrawableCache, *args, **kwargs)¶
Bases:
Drawable
A Drawable representing an eraser that can remove specified drawable objects.
- drawable_cache¶
Cache used for calculating bounding box of objects to erase.
- Type:
The draw method generates a zigzag motion over the bounding box of the objects to be erased, using an expanded pen width to create a pastel blend erasing effect.
handanim.primitives.lines module¶
- class handanim.primitives.lines.Line(start: tuple[float, float], end: tuple[float, float], *args, **kwargs)¶
Bases:
Drawable
A drawable line primitive that generates hand-drawn style lines with randomized jitter and bowing effects.
Supports customizable stroke and sketch styles, with options for line curvature, roughness, and multiple line passes to create a hand-drawn appearance. Allows for optional stroke pressure variations and provides methods to draw single or overlapping lines.
- start¶
Starting point coordinates of the line
- Type:
np.ndarray
- end¶
Ending point coordinates of the line
- Type:
np.ndarray
- class handanim.primitives.lines.LinearPath(points: List[tuple[float, float]], close: bool = False, *args, **kwargs)¶
Bases:
Drawable
A drawable linear path that connects a series of points, with optional closing of the path.
- points¶
A list of (x, y) coordinate points defining the path.
- Type:
List[tuple[float, float]]
- close¶
Whether to connect the last point back to the first point. Defaults to False.
- Type:
bool, optional
- Raises:
ValueError – If fewer than two points are provided.
The path is drawn by creating Line objects between consecutive points, with optional path closure if specified.
handanim.primitives.math module¶
- class handanim.primitives.math.Math(tex_expression: str, position: Tuple[float, float], font_size: int = 12, font_name: str = 'handanimtype1', *args, **kwargs)¶
Bases:
Drawable
A Drawable class for rendering mathematical expressions using TeX notation.
This class parses a TeX expression and renders individual glyphs using a specified font, supporting custom positioning, scaling, and stroke styling.
- tex_expression¶
The TeX mathematical expression to render
- Type:
str
- position¶
The starting position for rendering the expression
- Type:
Tuple[float, float]
- font_size¶
The size of the font, defaults to 12
- Type:
int, optional
- font_name¶
The name of the font to use for rendering, defaults to “feasibly”
- Type:
str
- get_glyph_opsset()¶
Extracts the operations set for a single unicode glyph
- draw()¶
Renders the entire mathematical expression as a set of drawing operations
- draw() OpsSet ¶
Provides the list of operations to be performed to draw this particular drawable object on the canvas
- get_glyph_opsset(unicode: int, font_size: int) Tuple[OpsSet, float, float] ¶
Returns the opset for a single glyph of a unicode number
- load_font()¶
handanim.primitives.polygons module¶
- class handanim.primitives.polygons.NGon(center: tuple[float, float], radius: float, n: int, *args, **kwargs)¶
Bases:
Polygon
- class handanim.primitives.polygons.Polygon(points: List[tuple[float, float]], *args, **kwargs)¶
Bases:
Drawable
A Polygon class representing a drawable polygon shape.
This class allows creating polygons with a list of points, drawing them with optional stroke and fill styles. It ensures the polygon has at least three points and can render the polygon using a closed linear path with optional filling.
- points¶
A list of (x, y) coordinates defining the polygon vertices.
- Type:
List[tuple[float, float]]
- Raises:
ValueError – If fewer than three points are provided.
- class handanim.primitives.polygons.Rectangle(top_left: tuple[float, float], width: float, height: float, *args, **kwargs)¶
Bases:
Polygon
A Rectangle class representing a rectangular polygon shape.
This class creates a rectangle by specifying its top-left corner coordinates, width, and height. It inherits from the Polygon class and generates the four vertices of the rectangle automatically.
- Parameters:
top_left (tuple[float, float]) – Coordinates of the top-left corner of the rectangle.
width (float) – Width of the rectangle.
height (float) – Height of the rectangle.
handanim.primitives.text module¶
- class handanim.primitives.text.CustomPen(glyphSet, scale: float = 0.01)¶
Bases:
BasePen
- class handanim.primitives.text.Text(text: str, position: Tuple[float, float], font_size: int = 12, *args, **kwargs)¶
Bases:
Drawable
A Drawable text primitive that renders text using font glyphs with customizable styling.
Supports rendering text with random font selection, scaling, and sketch-style variations. Converts text characters into drawing operations (OpsSet) that can be rendered.
- text¶
The text to be rendered
- Type:
str
- position¶
Starting position for text rendering
- Type:
Tuple[float, float]
- font_size¶
Size of the rendered text. Defaults to 12.
- Type:
int, optional
- scale_factor¶
Additional scaling factor. Defaults to 1.0.
- Type:
float, optional
- get_random_font_choice()¶
Selects a font for text rendering
- get_glyph_strokes(char)¶
Converts a character into drawing operations
- get_glyph_space()¶
Calculates character and space widths
- draw()¶
Generates the complete set of drawing operations for the text
- draw() OpsSet ¶
Provides the list of operations to be performed to draw this particular drawable object on the canvas
- get_glyph_space() Tuple[float, float] ¶
Gives the width of the space, or an average width
- get_glyph_strokes(char) Tuple[OpsSet, float] ¶
Gives the glyph operations as well the width of the char for offsetting purpose
- get_random_font_choice() Tuple[str, str] ¶
Chooses a random font from the available fonts
Module contents¶
- class handanim.primitives.Circle(center: tuple[float, float], radius: float, *args, **kwargs)¶
Bases:
Ellipse
A specialized Ellipse where the x and y radii are equal, creating a perfect circle.
- Parameters:
center (tuple[float, float]) – The center coordinates of the circle.
radius (float) – The radius of the circle.
- class handanim.primitives.Curve(points: List[Tuple[float, float]], *args, **kwargs)¶
Bases:
Drawable
A class representing a curve that can be drawn with a sketchy, hand-drawn style.
Allows creating curves with multiple points, supporting various drawing techniques including single line, quadratic, and more complex multi-point curves with randomization to simulate hand-drawn appearance.
- points¶
List of points defining the curve’s shape.
- Type:
List[np.ndarray]
- class handanim.primitives.Ellipse(center: Tuple[float, float], width: float, height: float, *args, **kwargs)¶
Bases:
Drawable
A drawable ellipse primitive with sketchy rendering capabilities.
Supports customizable center, width, height, and sketch-style rendering with optional multi-stroke and roughness effects. Allows for generating ellipses with randomized point generation and stroke variations.
- center¶
The center point of the ellipse
- Type:
np.ndarray
- width¶
The width of the ellipse
- Type:
float
- height¶
The height of the ellipse
- Type:
float
- class handanim.primitives.Eraser(objects_to_erase: List[Drawable], drawable_cache: DrawableCache, *args, **kwargs)¶
Bases:
Drawable
A Drawable representing an eraser that can remove specified drawable objects.
- drawable_cache¶
Cache used for calculating bounding box of objects to erase.
- Type:
The draw method generates a zigzag motion over the bounding box of the objects to be erased, using an expanded pen width to create a pastel blend erasing effect.
- class handanim.primitives.Line(start: tuple[float, float], end: tuple[float, float], *args, **kwargs)¶
Bases:
Drawable
A drawable line primitive that generates hand-drawn style lines with randomized jitter and bowing effects.
Supports customizable stroke and sketch styles, with options for line curvature, roughness, and multiple line passes to create a hand-drawn appearance. Allows for optional stroke pressure variations and provides methods to draw single or overlapping lines.
- start¶
Starting point coordinates of the line
- Type:
np.ndarray
- end¶
Ending point coordinates of the line
- Type:
np.ndarray
- class handanim.primitives.Math(tex_expression: str, position: Tuple[float, float], font_size: int = 12, font_name: str = 'handanimtype1', *args, **kwargs)¶
Bases:
Drawable
A Drawable class for rendering mathematical expressions using TeX notation.
This class parses a TeX expression and renders individual glyphs using a specified font, supporting custom positioning, scaling, and stroke styling.
- tex_expression¶
The TeX mathematical expression to render
- Type:
str
- position¶
The starting position for rendering the expression
- Type:
Tuple[float, float]
- font_size¶
The size of the font, defaults to 12
- Type:
int, optional
- font_name¶
The name of the font to use for rendering, defaults to “feasibly”
- Type:
str
- get_glyph_opsset()¶
Extracts the operations set for a single unicode glyph
- draw()¶
Renders the entire mathematical expression as a set of drawing operations
- draw() OpsSet ¶
Provides the list of operations to be performed to draw this particular drawable object on the canvas
- get_glyph_opsset(unicode: int, font_size: int) Tuple[OpsSet, float, float] ¶
Returns the opset for a single glyph of a unicode number
- load_font()¶
- class handanim.primitives.NGon(center: tuple[float, float], radius: float, n: int, *args, **kwargs)¶
Bases:
Polygon
- class handanim.primitives.Polygon(points: List[tuple[float, float]], *args, **kwargs)¶
Bases:
Drawable
A Polygon class representing a drawable polygon shape.
This class allows creating polygons with a list of points, drawing them with optional stroke and fill styles. It ensures the polygon has at least three points and can render the polygon using a closed linear path with optional filling.
- points¶
A list of (x, y) coordinates defining the polygon vertices.
- Type:
List[tuple[float, float]]
- Raises:
ValueError – If fewer than three points are provided.
- class handanim.primitives.Rectangle(top_left: tuple[float, float], width: float, height: float, *args, **kwargs)¶
Bases:
Polygon
A Rectangle class representing a rectangular polygon shape.
This class creates a rectangle by specifying its top-left corner coordinates, width, and height. It inherits from the Polygon class and generates the four vertices of the rectangle automatically.
- Parameters:
top_left (tuple[float, float]) – Coordinates of the top-left corner of the rectangle.
width (float) – Width of the rectangle.
height (float) – Height of the rectangle.
- class handanim.primitives.Square(top_left: tuple[float, float], side_length: float, *args, **kwargs)¶
Bases:
Rectangle
- class handanim.primitives.Text(text: str, position: Tuple[float, float], font_size: int = 12, *args, **kwargs)¶
Bases:
Drawable
A Drawable text primitive that renders text using font glyphs with customizable styling.
Supports rendering text with random font selection, scaling, and sketch-style variations. Converts text characters into drawing operations (OpsSet) that can be rendered.
- text¶
The text to be rendered
- Type:
str
- position¶
Starting position for text rendering
- Type:
Tuple[float, float]
- font_size¶
Size of the rendered text. Defaults to 12.
- Type:
int, optional
- scale_factor¶
Additional scaling factor. Defaults to 1.0.
- Type:
float, optional
- get_random_font_choice()¶
Selects a font for text rendering
- get_glyph_strokes(char)¶
Converts a character into drawing operations
- get_glyph_space()¶
Calculates character and space widths
- draw()¶
Generates the complete set of drawing operations for the text
- draw() OpsSet ¶
Provides the list of operations to be performed to draw this particular drawable object on the canvas
- get_glyph_space() Tuple[float, float] ¶
Gives the width of the space, or an average width
- get_glyph_strokes(char) Tuple[OpsSet, float] ¶
Gives the glyph operations as well the width of the char for offsetting purpose
- get_random_font_choice() Tuple[str, str] ¶
Chooses a random font from the available fonts