All lab
Lab 01Open sourceJavaScriptCanvas

Any image, as sand.

sand-portrait is the dot effect from my homepage, turned into a small open-source library. Dots rise from a pile of sand into a portrait, then scatter from your cursor and spring back.

Hover · click · drop a photo
Live demo

Try it.

Hover to push the dots, click to send a ripple, or drop your own photo on the stage. Cut-out photos look best.

No dependenciesCanvas 2DMIT
< 6 KBGzipped, one file
0Dependencies
v1.0.0MIT licence
Role
Designed and built by me
Stack
Vanilla JavaScript, Canvas 2D
Licence
MIT, free to use
Code
GitHub ↗
Origin
The dot portrait and wordmark on this site

How it
works

Four steps on one canvas, with no libraries underneath.

  1. Sample

    The image is drawn small, one pixel per dot. Each pixel's brightness sets its dot's size, so the portrait stays a positive image in light or dark.

    Halftone grid
  2. Pile

    Every dot starts on the floor in a low mound of sand, denser in the middle, like a pile that was just poured.

    Intro
  3. Rise

    Dots rise in a staggered arc, lowest rows first, and land exactly on their spot in the image.

    Easing · stagger
  4. React

    A spring pulls each dot home, so the cursor can push them aside and they settle back. A click sends a ripple.

    Spring physics

Built for
real pages

The details that make it safe to put on a production site.

Respects reduced motion

People who ask for less motion get the finished image straight away: no intro, no interaction.

Sleeps when idle

It stops drawing when nothing moves, and pauses when it is off screen or the tab is hidden.

Redraws on resize

Size the canvas with CSS. The dot grid rebuilds when the size changes.

Plain backgrounds stay empty

A studio or wall background is detected from the corners, so only the subject turns to sand.

Words and logos too

SandPortrait.text turns any word into a source, with even dots for type.

Use it

A script tag, or import it as a module. Size the canvas with CSS and pass an image.

<!-- script tag -->
<canvas id="me" style="width:400px;height:500px"></canvas>
<script src="https://cdn.jsdelivr.net/gh/hellosaifuli/sand-portrait@v1.0.0/sand-portrait.js"></script>
<script>
  SandPortrait(document.getElementById('me'), { src: 'me.png' });
</script>

// or as a module
import SandPortrait from 'https://cdn.jsdelivr.net/gh/hellosaifuli/sand-portrait@v1.0.0/sand-portrait.mjs';
const sand = SandPortrait(canvas, { src: 'me.png', on: 'dark', color: '#fff' });
sand.replay();

Keep
exploring

The code, how it was built, and where it runs.

Remote from Dhaka, GMT+6 · Open to roles

Need a designer
who ships?