Dereliction — giving every pixel on a web page mass

3 min read Original article ↗

What it is

It renders the viewport to pixels in the browser, hands a million of them to a WebGL2 simulation, and gives the words to a rigid-body engine. Gravity can pull on dark pixels only, wind can blow away everything that is not text, letters can fall into a pile, and sand can pour over them for as long as you like.

It is meant to happen to an ordinary page: leave it idle and it comes apart; the first scroll or key press brings it back.

Use it

<script src="https://cdn.jsdelivr.net/npm/dereliction@0.5.1/dist/dereliction.bundle.min.js" defer
        data-attach data-idle="8000" data-preset="Avalanche"></script>

One file, one tag, no build step, no server. Or npm i dereliction and call Dereliction.attach({…}) yourself.

Tell it what should hold and what should go, in your own stylesheet:

.sticky  { --physics: solid; }   /* never moves; sand piles on it      */
.card    { --physics: rigid; }   /* one body, falls as a block         */
.block   { --physics: frame; }   /* falls as a box; words fall inside  */
.fine    { --physics: sand;  }   /* its text is loose grains           */

This italic line is marked sand. It will not survive the avalanche; it goes with the paper.

Presets

words fall as rigid bodies while the paper pours over them as sand
every glyph is its own body
every line becomes a block and tumbles away in a light breeze
an endless trickle of sand through a narrow spout, onto the text
the paper is thrown up and pours down as sand onto text that holds
the same, but the sand keeps coming back in across the top edge
wind on everything that is not text; lightness becomes depth
only the dark pixels get gravity; the light ones are viscous
gravity on everything, drag by lightness
a critically damped spring back to the page

This card is rigidText, border and shadow fall together as one block and land on whatever got to the bottom first. Drag it with the mouse while things are falling.

Under the hood

Two renders of the page, one with the text made transparent, are diffed into a pixel-exact ink mask. Particle state lives in float textures; one fragment shader is the physics step. Bodies come from matter.js and are rasterised every frame into an obstacle map, which is what the sand piles on. Chrome, Firefox and Safari 15+, anything with WebGL2.

Prefer pixel-perfect captures? A build-time prerender or a small Playwright service are included too. Neither is required.