ca

canvas_ity - A tiny, single-header canvas-like 2D rasterizer for C++

Hacker News

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 card

Actual performance

8points
2comments
Made the leaderboard

Launch Intel predictions

Analyze your own launch →
Product HuntOn track for Day 1 leaderboard · Strong signals: single, tiny, code · Missing: mac, agents, macos
92%92% predicted probability of success on Product Hunt, based on ML models trained on real launch data.
best fitHighest predicted score across all platforms for this description.
Hacker NewsStrong engagement from HN community · Strong signals: open source, io · Missing: https docs, excited, just released
68%68% predicted probability of success on Hacker News, based on ML models trained on real launch data.
nativeThis product was originally launched on this platform.
Indie HackersFits the IH revenue-focused audience · Missing: supports, reddit linkedin, podcasting
62%62% predicted probability of success on Indie Hackers, based on ML models trained on real launch data.
TrustMRRLess likely to generate early MRR · Strong signals: way · Missing: mobile apps, ios, personal
43%43% predicted probability of success on TrustMRR, based on ML models trained on real launch data.
AppSumoMay struggle as an AppSumo deal · Missing: plus, platform, intuitive
29%29% predicted probability of success on AppSumo, based on ML models trained on real launch data.
Acquire.comPre-revenue stage for this audience · Missing: arr, mrr, revenue
14%14% predicted probability of success on Acquire.com, based on ML models trained on real launch data.
BetaListMay not resonate with beta-testers · Missing: web3, chat, crypto
1%1% predicted probability of success on BetaList, based on ML models trained on real launch data.

Correct prediction on native model

Similar products

Px
Px - A tiny 2D canvas framework for puzzle games65%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Px - A tiny 2D canvas framework for puzzle games

Hacker News5
EV
EVILVIL.space – My tiny 2D Zombie Game69%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

EVILVIL.space – My tiny 2D Zombie Game

Hacker News16
PD
PDFx – a 2D canvas for multiple PDFs, stored inside a single PDF59%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

PDFx – a 2D canvas for multiple PDFs, stored inside a single PDF

Hacker News1
49
49 IDE – 2D Canvas for Agents65%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

49 IDE – 2D Canvas for Agents

Hacker News18
Si
Simulating Galaxies in 2D67%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Simulating Galaxies in 2D

Hacker News4
8Land
8Land9%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

8Land is a 2D pixelart metaverse

Indie Hackers1art
A
A tiny canvas (js) experiment called “Einstein Waves”53%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

A tiny canvas (js) experiment called “Einstein Waves”

Hacker News3
Mu
Multistate – Save and restore WebGL state like in a 2D canvas57%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Multistate – Save and restore WebGL state like in a 2D canvas

Hacker News2
Ti
Tiny – A 2D Game Engine in Kotlin Working with Lua78%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Tiny – A 2D Game Engine in Kotlin Working with Lua

Hacker News100
Ex
Experiment: Toggle interactive 2D canvas using Fullscreen API66%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Experiment: Toggle interactive 2D canvas using Fullscreen API

Hacker News1