CLI tool
mattdesl/canvas-sketch avatar
mattdesl/canvas-sketch

canvas-sketch: a JavaScript framework for generative artwork in the browser

[beta] A framework for making generative artwork in JavaScript and the browser.

5,327 stars403 forksJavaScriptMIT

At a glance

What is it?
canvas-sketch is a CLI plus a small runtime for prototyping 2D and WebGL sketches in JavaScript. It is a strong fit for print-oriented generative work and a poor fit for anyone who needs a stable, documented API surface.
Who is it for?
Adopt canvas-sketch if you are an individual artist or designer who wants a browser canvas, a hot-reloading dev server and print-resolution PNG export without assembling a build pipeline yourself. Do not adopt it if you need documented, versioned APIs, unit-tested behaviour or a support commitment: the README lists API and CLI docs, beginner-friendly examples and unit tests as outstanding roadmap items, and the package version is still 0.7.8.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 166 days ago.
What is it written in?
Mainly JavaScript, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 15, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • mattdesl/canvas-sketch5,327 ★ · +42
Star history
Repository2026-09-232026-11-15
mattdesl/canvas-sketch5.3k5.3k

42 Stars in the last 53 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

What canvas-sketch actually solves for generative artists

The README describes canvas-sketch as "a loose collection of tools, modules and resources for creating generative art in JavaScript and the browser." That word, loose, is doing real work. The project is not a rendering engine. It is a thin layer that sits between your artwork function and the browser canvas, and it handles the parts of a generative sketch that are tedious to wire up every time, such as sizing the artwork in physical units and exporting the result at a size you can actually print.

The intended user is someone who thinks in terms of drawing code rather than application architecture. The code example in the README is a single artwork function that receives context, width and height, fills a background, builds a linear gradient and draws a rectangle. There is no scene graph, no component model and no state container. If you have written a Processing sketch or a p5.js sketch, the shape of the code will be familiar.

The print angle is the part that distinguishes it from a plain canvas wrapper. The example sets dimensions to 'a4', pixelsPerInch to 300 and units to 'in', and the README states that exporting with Cmd + S or Ctrl + S saves a PNG matching 21 x 29.7 cm at 300 DPI, suitable for printing with archival ink. That is a specific, checkable claim, and it is the reason the framework exists in this form rather than as a general animation library.

The sketch function contract and how a frame gets drawn

The mechanism is small enough to describe completely. You require the canvas-sketch module, define a settings object and define a sketch function. The sketch function returns another function. That returned function is the render callback, and it receives an object containing context, width and height.

That two-level structure is the whole architecture. The inner function is where drawing happens, and it is handed width and height rather than reading them from the canvas element.

Settings are where the framework earns its keep. The README example uses dimensions, pixelsPerInch and units. Dimensions accepts a named paper size such as 'a4', and units sets the unit, 'in' in the example. The package depends on convert-length, which is consistent with unit conversion happening inside the framework rather than in your sketch.

What the README does not give is the full settings schema. It points to the documentation directory for that. Anyone evaluating the project should treat the README as a starting point and the docs/ folder as the actual reference, because the README only demonstrates a handful of keys.

Installing canvas-sketch-cli and exporting your first PNG

The README's quick start targets [email protected] and [email protected] or newer. The CLI is a separate package named canvas-sketch-cli, and the README explicitly warns about the x in npx and the -cli suffix, because both are easy to get wrong.

The first block creates a working folder and scaffolds a new sketch file, then opens it in the browser:

bash
mkdir my-sketches
cd my-sketches
npx canvas-sketch-cli sketch.js --new --open

After that command you should have a sketch.js in the folder and a browser tab showing the default sketch. With the browser focused, pressing Cmd + S on macOS or Ctrl + S elsewhere writes a high-resolution PNG into your ~/Downloads folder. That keystroke export is the core workflow, not a side feature.

Once a file exists, the CLI can run against it directly, and the output directory is configurable:

bash
npx canvas-sketch-cli src/foobar.js --output=./tmp/

The README also documents starting from a template, building a static site, and using hot reloading rather than a full page reload:

bash
npx canvas-sketch-cli --new --template=three --open
npx canvas-sketch-cli src/foobar.js --build
npx canvas-sketch-cli src/foobar.js --hot

The --build flag produces a sharable HTML plus JS bundle, which is the path to putting a sketch online. The README notes that npx is convenient but that you may prefer a global install, and points to docs/installation.md for that; the installation details are not in the README itself.

Where canvas-sketch is the wrong tool

The repository is honest about its own gaps in a way that most project READMEs are not. The roadmap lists API and CLI docs, easy and beginner-friendly examples, a website frontend, HUD and GUI controls, a gallery mode for viewing many local sketches, an external utilities module, and unit tests as features still outstanding. Unit tests are on that list. If your work depends on documented, tested, versioned behaviour, this is a beta, and the package version 0.7.8 reflects that.

The beta label is in the repository description itself. Practically, that means the settings keys and CLI flags you build on today are not guaranteed to survive an upgrade. The repository has no published GitHub releases, so there is no changelog to read before you bump the version.

There is also a structural limit in the export path. Exporting is triggered from the browser with a keyboard shortcut. That makes the tool a good fit for interactive, one-artwork-at-a-time work by a person sitting at a machine. It is a poor fit for batch generation on a server, for a CI job that renders hundreds of variations, or for any pipeline where nobody is present to press Cmd + S. The README does not document a headless export command, and it does not document rollback or version pinning behaviour either.

Finally, the framework does not try to be a drawing library. If you need geometry helpers, noise functions, random distributions or colour utilities, the README's roadmap says an external module for utilities such as randomness and geometry is still planned. The devDependencies include canvas-sketch-util, but the README does not present it as part of the core install.

canvas-sketch compared with p5.js

The closest point of comparison is p5.js, and the difference is architectural rather than cosmetic. p5.js is a full creative-coding environment: it supplies a large drawing API, its own naming conventions for shapes and colour, and a sketch lifecycle built around setup and draw. You write against p5's vocabulary, and the library decides a great deal about how your program is structured.

canvas-sketch takes the opposite approach. It hands you the raw browser canvas context and gets out of the way. You call context.fillRect, context.createLinearGradient and context.fillStyle directly, as the README example does. There is no drawing API to learn because there is no drawing API. What you get instead is the surrounding infrastructure: paper-size dimensions, DPI-aware export, a dev server, hot reloading and a build step.

That makes the two tools suited to different jobs. If you want a rich set of drawing primitives and a gentle learning curve, p5.js gives you more out of the box. If you already know the canvas API or you are working in WebGL and you mainly want the print export and the dev loop handled, canvas-sketch adds less between you and the pixels. The examples directory shows the project is not doctrinaire about this: it contains animated-p5.js and animated-p5-instance.js alongside three.js, two.js and regl examples, so p5 can be driven from inside a canvas-sketch sketch.

Maintenance, licence and the cost of upgrading

canvas-sketch is MIT licensed, and the LICENSE.md file at the repository root carries the terms. A permissive licence of that kind places few obligations on how you distribute work made with the framework, but it also means there is no commercial support channel attached. For a full reading of what MIT does and does not require, read LICENSE.md rather than a summary.

The repository is not archived, and the last push was on 2026-06-02. That is recent enough that the codebase is not abandoned, but the roadmap items listed in the README (API and CLI docs, unit tests, a utilities module) are described as outstanding, and the repository has no published releases. Treat the project as maintained but not feature-complete.

The upgrade cost follows from that. With no changelog to consult and a 0.x version number, the practical approach is to pin the version in your package.json and read the diff before moving. The dependency list is short for the core package (convert-length, dateformat, deep-equal, get-canvas-context, is-class, is-dom, is-promise, right-now), which keeps the surface small, but the CLI is a separate package and needs pinning separately. If you build a body of sketches on this framework, budget for the possibility that a settings key changes meaning between minor versions, and keep the exported PNGs as the durable artefact rather than assuming the source will run unchanged in two years.

Editorial conclusion

Adopt canvas-sketch if you are an individual artist or designer who wants a browser canvas, a hot-reloading dev server and print-resolution PNG export without assembling a build pipeline yourself. Do not adopt it if you need documented, versioned APIs, unit-tested behaviour or a support commitment: the README lists API and CLI docs, beginner-friendly examples and unit tests as outstanding roadmap items, and the package version is still 0.7.8. Before committing, verify two things in your own checkout: that the sketch entry point you want (2D canvas, three.js, two.js, regl, p5) has a working example under examples/, and that the pixelsPerInch and units settings you plan to print with produce the physical dimensions you expect. The export path runs through the browser, so confirm the PNG that lands in ~/Downloads at your target DPI before you send anything to a printer.

Frequently asked questions

How do I install canvas-sketch and start a new sketch?

The README's quick start uses npx rather than a global install. Create a folder, move into it, and run npx canvas-sketch-cli sketch.js --new --open with [email protected] and [email protected] or newer. The README notes the x in npx and the -cli suffix in canvas-sketch-cli, both of which are easy to mistype.

How do I export a high-resolution PNG from canvas-sketch?

With the sketch open in the browser, press Cmd + S on macOS or Ctrl + S elsewhere, and the README states the PNG is written to your ~/Downloads folder. The saved file's physical size depends on the dimensions, pixelsPerInch and units settings in your sketch; the README's A4 example at 300 DPI produces an image matching 21 x 29.7 cm.

What is canvas-sketch used for?

The repository describes it as a framework for making generative artwork in JavaScript and the browser, and the package description calls it a utility for quickly prototyping 2D and WebGL sketches. The examples directory covers 2D canvas work plus three.js, two.js, regl and p5 sketches.

Does canvas-sketch support Three.js, two.js and regl?

Yes. The examples directory includes animated-three-basic-cube.js, animated-three-sphere-shader.js, animated-three-text-canvas.js, animated-two-basic-rect.js, animated-two-bitmap.js, animated-regl-fullscreen-shader.js and animated-regl-dither-blob.js. The README also documents scaffolding from a template with npx canvas-sketch-cli --new --template=three --open.

Which licence does canvas-sketch use?

MIT. The README states the licence and points to LICENSE.md in the repository for the terms.

Official sources

  1. Issues
  2. License: MIT
  3. mattdesl/canvas-sketch on GitHub
  4. README
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/mattdesl-canvas-sketch.svg)](https://hysenlabs.com/projects/mattdesl-canvas-sketch)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/mattdesl-canvas-sketch.svg)](https://hysenlabs.com/projects/mattdesl-canvas-sketch)

Was this useful?