Heuristic:AI Builder Club Skills 2x Supersampling
| Knowledge Sources | |
|---|---|
| Domains | Graphics, Optimization |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
Render diagrams at 2x internal resolution then downscale with LANCZOS resampling for anti-aliased quality without per-pixel cost.
Description
The 2x supersampling technique renders all diagram elements (nodes, edges, text, animation particles) at twice the target resolution, then downscales the final image to the target size using Pillow's LANCZOS resampling filter. This produces smooth, anti-aliased edges and crisp text without requiring sub-pixel rendering logic. The px() function multiplies all coordinate values by RENDER_SCALE=2, and the final image.resize() call downscales back to the spec canvas dimensions.
Usage
Apply this heuristic when rendering diagrams (render_animated_gif.py) where output quality matters — especially for text, rounded corners, and thin lines. Use when the output is a PNG or GIF that will be viewed at 1:1 scale but should appear smooth.
The Insight (Rule of Thumb)
- Action: Set
RENDER_SCALE = 2; multiply all coordinates, sizes, and font sizes by this factor during rendering; downscale the final image with LANCZOS. - Value:
RENDER_SCALE = 2— render at 2x, output at 1x. - Trade-off: 4x more pixels to render (2x in each dimension), ~4x memory usage during rendering. The final downscale step is fast (LANCZOS is optimized). Net: negligible time cost, significant quality improvement.
- Downscale filter: Use
Image.Resampling.LANCZOS(requires Pillow >= 10.0). This is the highest-quality resampling filter in Pillow. - Font scaling:
ImageFont.truetype(path, px(size))— font sizes are also scaled byRENDER_SCALE, ensuring text rasterizes at high resolution before downscaling.
Reasoning
Supersampling is a well-established anti-aliasing technique. By rendering at a higher resolution, each output pixel after downscaling is the average of multiple source pixels, effectively averaging sub-pixel positions and producing smooth edges. LANCZOS resampling uses a sinc-based kernel that preserves sharpness while reducing aliasing artifacts. The 2x factor is a practical sweet spot: 4x more pixels but still fast for the diagram sizes used (1280x800 → 2560x1600 internal). Higher factors (3x, 4x) yield diminishing returns with increasing memory/time cost. The technique is applied per-frame for animated GIFs, so each of the 48 default frames benefits from the quality improvement.