bencher.results.manim_cartesian.cartesian_product_scene

Dimensional extrusion animation using PIL.

Shows how each dimension builds on the last:

point –dim1–> line –dim2–> grid –dim3–> stack –repeat–> extrude –over_time–> film strip –dim4+–> sets of sets …

Renders frames directly with PIL (fast), saves as animated PNG (APNG).

Attributes

logger

CELL_SIZE

CELL_GAP

DIM_PALETTE

CELL_BORDER

BG_COLOR

LABEL_COLOR

DEPTH_DX

DEPTH_DY

GROUP_GAP

GAP

FILM_COLOR

FILM_EDGE

FILM_FRAME_BORDER

FILM_LABEL_COLOR

FILM_PAD

FILM_FRAME_PAD

FILM_FRAME_GAP

FILM_SPROCKET_W

FILM_SPROCKET_H

FILM_SPROCKET_R

FILM_SPROCKET_SPACING

FILM_SPROCKET_MARGIN

FILM_LABEL_H

Classes

Shape

Recursive shape representation for dimensional extrusion.

TimelineShape

Film-strip timeline for the over_time dimension.

StrobeShape

Shape with a glowing border and tally-mark counter.

Functions

render_shape_to_image(→ PIL.Image.Image)

Render shape into an offscreen image scaled to fit target_w x target_h.

_generate_unique_filename(→ str)

Generate a unique filename based on animation parameters.

_get_font(size)

Get a font, falling back to default if no TTF available.

_direction_for(→ str)

Map dimension index to layout direction.

render_animation(→ str)

Render the dimensional extrusion animation.

Module Contents

bencher.results.manim_cartesian.cartesian_product_scene.logger
bencher.results.manim_cartesian.cartesian_product_scene.CELL_SIZE = 20
bencher.results.manim_cartesian.cartesian_product_scene.CELL_GAP = 3
bencher.results.manim_cartesian.cartesian_product_scene.DIM_PALETTE = [(150, 190, 240), (240, 160, 155), (150, 220, 160), (245, 225, 140), (220, 170, 235), (245, 200,...
bencher.results.manim_cartesian.cartesian_product_scene.CELL_BORDER = (180, 180, 180)
bencher.results.manim_cartesian.cartesian_product_scene.BG_COLOR = (255, 255, 255)
bencher.results.manim_cartesian.cartesian_product_scene.LABEL_COLOR = (30, 30, 30)
bencher.results.manim_cartesian.cartesian_product_scene.DEPTH_DX = 10
bencher.results.manim_cartesian.cartesian_product_scene.DEPTH_DY = -8
bencher.results.manim_cartesian.cartesian_product_scene.GROUP_GAP = 20
bencher.results.manim_cartesian.cartesian_product_scene.GAP = '...'
bencher.results.manim_cartesian.cartesian_product_scene.render_shape_to_image(shape: Shape, target_w: int, target_h: int, bg_color: tuple[int, int, int] = BG_COLOR, alpha: float = 1.0) PIL.Image.Image

Render shape into an offscreen image scaled to fit target_w x target_h.

The returned image is at most target_w x target_h and centered content-wise.

bencher.results.manim_cartesian.cartesian_product_scene._generate_unique_filename(cfg: bencher.results.manim_cartesian.cartesian_product_cfg.CartesianProductCfg, width: int, height: int) str

Generate a unique filename based on animation parameters.

bencher.results.manim_cartesian.cartesian_product_scene._get_font(size: int)

Get a font, falling back to default if no TTF available.

class bencher.results.manim_cartesian.cartesian_product_scene.Shape(children: list[Shape] | None = None, direction: str = 'right', depth: int = 0, color_index: int = 0)

Recursive shape representation for dimensional extrusion.

A Shape is either a leaf (single cell) or a collection of sub-shapes arranged along an axis. depth tracks nesting level so that higher-dimensional extrusions use wider gaps.

children = None
direction = 'right'
depth = 0
color_index = 0
_cached_size = None
property is_leaf: bool
property gap: int

Gap between children.

Depth 0-2 (first two spatial dims forming the basic grid): tight CELL_GAP. Depth 3 (stack direction): uses isometric offset, gap not used. Depth 4+ (sets of stacks, sets of sets): GROUP_GAP scaling with depth.

size() tuple[int, int]

Return (width, height) in pixels. Cached — tree structure is immutable.

draw(img: PIL.ImageDraw.ImageDraw, x: int, y: int, alpha: float = 1.0)

Draw this shape at position (x, y) on the image.

extrude(n: int, direction: str, color_index: int | None = None) Shape

Create a new shape by extruding this one n times along direction.

_deep_copy() Shape
_deep_copy_recolored(color_index: int) Shape

Copy and recolor in a single traversal.

bencher.results.manim_cartesian.cartesian_product_scene._direction_for(dim_index: int) str

Map dimension index to layout direction.

bencher.results.manim_cartesian.cartesian_product_scene.FILM_COLOR = (35, 35, 38)
bencher.results.manim_cartesian.cartesian_product_scene.FILM_EDGE = (25, 25, 28)
bencher.results.manim_cartesian.cartesian_product_scene.FILM_FRAME_BORDER = (90, 90, 95)
bencher.results.manim_cartesian.cartesian_product_scene.FILM_LABEL_COLOR = (100, 100, 100)
bencher.results.manim_cartesian.cartesian_product_scene.FILM_PAD = 6
bencher.results.manim_cartesian.cartesian_product_scene.FILM_FRAME_PAD = 10
bencher.results.manim_cartesian.cartesian_product_scene.FILM_FRAME_GAP = 16
bencher.results.manim_cartesian.cartesian_product_scene.FILM_SPROCKET_W = 8
bencher.results.manim_cartesian.cartesian_product_scene.FILM_SPROCKET_H = 14
bencher.results.manim_cartesian.cartesian_product_scene.FILM_SPROCKET_R = 2
bencher.results.manim_cartesian.cartesian_product_scene.FILM_SPROCKET_SPACING = 14
bencher.results.manim_cartesian.cartesian_product_scene.FILM_SPROCKET_MARGIN = 4
bencher.results.manim_cartesian.cartesian_product_scene.FILM_LABEL_H = 18
class bencher.results.manim_cartesian.cartesian_product_scene.TimelineShape(inner: Shape, count: int)

Bases: Shape

Film-strip timeline for the over_time dimension.

Each time step is a “frame” in a horizontal film strip with sprocket holes along top and bottom edges — unmistakably film.

The film chrome (sprockets, borders, padding) is always rendered at a fixed pixel size. The inner shape is scaled to fit within a constant frame window so the strip looks the same regardless of content complexity.

FRAME_W = 100
FRAME_H = 80
inner
count
_skip_labels = False
property is_leaf: bool
_outer_frame_size() tuple[int, int]

Size of each frame including padding.

size() tuple[int, int]

Return (width, height) in pixels. Cached — tree structure is immutable.

draw(img: PIL.ImageDraw.ImageDraw, x: int, y: int, alpha: float = 1.0)

Draw this shape at position (x, y) on the image.

static _draw_sprockets(img: PIL.ImageDraw.ImageDraw, strip_x: int, row_y: int, strip_w: int)

Draw a row of rounded sprocket holes across the strip width.

strip_size() tuple[int, int]

Size of the film strip excluding the label row below.

draw_without_labels(img: PIL.ImageDraw.ImageDraw, x: int, y: int) None

Draw the film strip without frame labels, preserving previous state.

render_strip_image(v_scale: float = 1.0) PIL.Image.Image

Render the strip (without labels) into an offscreen image.

The strip is drawn at full resolution and then uniformly scaled by v_scale (typically chosen to fit the canvas height). The returned image can be pasted directly — PIL clips any overflow naturally.

draw_label_overlay_for_viewport(img: PIL.ImageDraw.ImageDraw, strip_x: int, strip_y: int, strip_h: int, scale: float, canvas_w: int) None

Draw frame labels at fixed pixel size for frames visible on canvas.

_deep_copy() Shape
class bencher.results.manim_cartesian.cartesian_product_scene.StrobeShape(inner: Shape, count: int, cfg: bencher.results.manim_cartesian.cartesian_product_cfg.CartesianProductCfg, flash: float = 0.0)

Bases: Shape

Shape with a glowing border and tally-mark counter.

flash (0–1) controls the glow intensity for animation frames. All visual tunables are read from cfg (a CartesianProductCfg).

inner
count
cfg
flash = 0.0
_skip_tally = False
property is_leaf: bool
size() tuple[int, int]

Return (width, height) in pixels. Cached — tree structure is immutable.

draw(img: PIL.ImageDraw.ImageDraw, x: int, y: int, alpha: float = 1.0)

Draw this shape at position (x, y) on the image.

_draw_tally(img, mx0, my, avail_w, color, c)

Proper tally marks (vertical lines, diagonal strike every 5) + xN label.

Tallies grow from the left. The xN number is always on the right. Only draws as many complete groups/marks as fit cleanly; the label alone conveys the count when space is tight.

content_box_size() tuple[int, int]

Size of border + inner shape, excluding the tally mark row.

draw_without_tally(img: PIL.ImageDraw.ImageDraw, x: int, y: int) None

Draw the shape without tallies, preserving previous state.

draw_tally_overlay(img: PIL.ImageDraw.ImageDraw, anchor_x: int, anchor_y: int, avail_w: int)

Draw tally marks at fixed pixel size on the final frame.

draw_tally_overlay_for_box(img: PIL.ImageDraw.ImageDraw, box_x: int, box_y: int, box_w: int, box_h: int) None

Draw fixed-size tally overlay below a rendered box.

Spacing is derived from cfg fields so layout stays consistent when configuration changes.

_deep_copy() Shape
bencher.results.manim_cartesian.cartesian_product_scene.render_animation(cfg: bencher.results.manim_cartesian.cartesian_product_cfg.CartesianProductCfg, width: int = 400, height: int = 300, fps: int = 15, step_frames: int = 4, output_dir: str = 'cachedir/cartesian') str

Render the dimensional extrusion animation.

Parameters:
  • cfg (CartesianProductCfg) – Sweep configuration.

  • width (int) – Video resolution.

  • height (int) – Video resolution.

  • fps (int) – Frames per second.

  • step_frames (int) – Frames to show each extrusion step (per sub-copy).

  • output_dir (str) – Directory for the output video.

Returns:

Path to the output animation file.

Return type:

str