Rough.js
Rough.js is a light weight (9kB) graphics library that lets you draw in a sketchy, hand-drawn-like, style. The library defines primitives to draw lines, curves, arcs, polygons, circles, and ellipses. It also supports drawing SVG paths.
Rough.js works with both Canvas and SVG.
@RoughLib on Twitter.
Install
The latest Rough.js can be downloaded from the dist folder.
or from npm:
npm install --save roughjs
Usage
const rc = rough;rc; // x, y, width, height
or SVG
const rc = rough;let node = rc; // x, y, width, heightsvg;
Lines and Ellipses
rc; // centerX, centerY, diameterrc; // centerX, centerY, width, heightrc; // x1, y1, x2, y2
Filling
rc; // fill with red hachurerc;rc;rc;rc;
Sketching style
rc;rc;rc;
SVG Paths
rc;rc;rc;rc;
SVG Path with simplification:
Using web workers
If you have Workly imported on your web page (~1k only), RoughJS will automatically offload all processing to a web worker - freeing up your main UI thread. This is great when creating complex drawings using RoughJs like maps. Read more about it here.
(source code for this map in examples)
Examples
API & Documentation
Credits
Some of the core algorithms were adapted from handy processing lib.
Algorithm to convert SVG arcs to Canvas described here was adapted from Mozilla codebase