
ittybitty
Graphite
A pencil sketch of any image, or the layers beneath.
This browser cannot run WebGL2, so this is a still image. The code below works wherever WebGL2 is available.
Code
The usage always matches the preview, layers and performance settings included. No build step or package.
Copy embed gives one block to paste into any page or site builder, no setup. For your own code: add graphite.js, ittybitty-shader.js, runtime.js, texture.js next to this page. Highlighted values follow the controls.
<!-- Quickest: one element. Size it with CSS; it fills its box. -->
<script type="module" src="./ittybitty-shader.js"></script>
<ittybitty-shader effect="graphite" style="width: 100%; aspect-ratio: 16 / 10;"></ittybitty-shader>
<!-- Or with JavaScript, for full control: -->
<canvas id="graphite" aria-hidden="true" style="width: 100%; aspect-ratio: 16 / 10; display: block"></canvas>
<script type="module">
import { graphite } from './graphite.js';
const canvas = document.getElementById('graphite');
const effect = graphite(canvas, {
showPaper: true,
showOutlines: true,
showShading: true,
image: '/examples/still-life.webp',
pressure: 0.9,
strokes: 0.5,
spacing: 3.5,
follow: 0.6,
angle: 55,
tooth: 0.5,
shake: 0.3,
variance: 0.5,
lead: '#2b2d33',
paper: '#f4f1ea',
// Performance
dpr: 2,
adaptive: true,
});
// Later: effect.set(…), effect.pause(), effect.resume(), effect.destroy()
</script>
Details
Soft contour lines drawn twice a hair apart, and short shading strokes that follow the forms, turning smoothly with them. The lead skips on the tooth of the paper and smudges in the darkest tones. Static: one draw per change.
- Payload
- 6.9 KB brotli for graphite.js and ittybitty-shader.js and runtime.js and texture.js, measured at build time. See the method.
- Resolution
- Device pixel ratio capped at 2.
- Frame rate
- None. One frame per change.
- When unseen
- Stops rendering when the canvas leaves the viewport or the tab is hidden, and resumes where it left off.
- Reduced motion
- Nothing to change: it never moves.
- Layers
- Up to five effects fuse into one shader and one draw call. Filters such as dithering and halftone process the layers beneath them.
- Browsers
- Any browser with WebGL2: Chrome and Edge 56+, Firefox 51+, Safari 15+.
- Licence
- MIT. Copy it, change it, ship it.