canvas_ity - A tiny, single-header canvas-like 2D rasterizer for C++
canvas_ity - A tiny, single-header canvas-like 2D rasterizer for C++
Hi HN! After a few years of off-and-on work on it, I'm pleased to release my canvas_ity library as open source. TLDR: This is a single-header C++ library with no dependencies beyond the standard C++ library. In about 2300 lines of 78-column code (not counting blanks or comments), or 1300 semicolons, it implements an API based on the basic W3C <canvas> specification to draw 2D vector graphics into an image buffer: - Strokes and fills (with antialiasing and gamma-correct blending) - Linear and radial gradients - Patterns (with repeat modes and bi-cubic resampling) - Line caps and line joins (handling high curvature) - Dash patterns and dash offsets - Transforms - Lines, quadratic and cubic Beziers, arcs, and rectangles - Text (very basic, but does its own TTF font file parsing) - Raster images (i.e., sprites) - Clipping (via masking) - Compositing modes (Porter-Duff) - Drop shadows with Gaussian blurs Why? Some years ago I needed to programmatically draw on an image file. I looked at Skia and was put off by its size and build complexity. Cairo was much better, but by then I was spoiled by the STB single-header libraries. I like tiny code and writing a single-header but powerful vector graphics library seemed like a fun challenge and a good way to pay things forward. I ended up with something that can compile down to less than 36 KiB of object code on x86-64 and uncovered a lot of interesting browser <canvas> quirks along the way with my testing suite. Enjoy!
Share cardActual performance
Launch Intel predictions
Analyze your own launch →Correct prediction on native model
Similar products
Px - A tiny 2D canvas framework for puzzle games
EVILVIL.space – My tiny 2D Zombie Game
PDFx – a 2D canvas for multiple PDFs, stored inside a single PDF
49 IDE – 2D Canvas for Agents
Simulating Galaxies in 2D
8Land is a 2D pixelart metaverse
A tiny canvas (js) experiment called “Einstein Waves”
Multistate – Save and restore WebGL state like in a 2D canvas
Tiny – A 2D Game Engine in Kotlin Working with Lua
Experiment: Toggle interactive 2D canvas using Fullscreen API