Dither morph: 3D models → interactive halftone dots
The user gives one or more 3D models. You deliver one self-contained HTML file (no server, no internet, opens by double-click, embeds in a site as an iframe) in which:
- each model is a regular grid of round dots; dot size is the tone (big, merging dots in shadow; tiny dots in light; dots fading out at the silhouette), black on white unless asked otherwise,
- the cursor pushes the dots under it apart a little, like a soft lens, healing behind it,
- changing model makes the shape rearrange into the next one, the dots swelling and shrinking as it passes.
First, ask
Start every job with a short intake, so the person knows what to supply and does not have to guess what is possible. Most people who install this have never seen the options. Ask once, in one round, before building.
How to ask:
- Ask only what the request has not already answered. If they wrote "dither-morph bust.glb and robot.glb, white on black, for my site", the models, colours and destination are settled; ask only what is left, or nothing.
- If your environment gives you a way to put multiple-choice questions to the user, use it so they can click answers; otherwise ask in plain text as a short numbered list. Put the usual choice first and mark it as the default.
- At most four questions. Everything else has good defaults and can be changed after they have seen a first version, which teaches more than any question.
- Plain words, no settings names. They are choosing a look, not configuring software.
- If they say "just make it" or do not answer, use the defaults and build.
The questions, in this order of importance:
- Models. "Which 3D models should I use? Give me the files or the folder (GLB, GLTF, OBJ, STL, PLY or 3MF).
One model gives a hover-only piece; two or more morph into each other." If there are model files in the
working folder, list them and ask which. If they have none: offer the built-in demo (
--demo) so they can see the effect now. If they only have pictures: this skill needs a mesh, so they need an image-to-3D tool first; say so plainly rather than trying to work from the picture. - Names and order. Only when there are two or more models: "What should each button say, and which one shows first?" Default: file names, in the order given.
- Look. "Black dots on white (default), light dots on dark, or your own colours?" If they name colours, use them as background and dot colour.
- Where it will live. "Is this just to look at, or should I put it into your website? If so, where is the
site and what is it built with (or just point me at the folder), and where on the page should it go?" To look
at: defaults. Into a site: build lighter (
--points 60000) and follow Put it in their site below; ask whether they want the built-in buttons or their own, and whether models should change by themselves.
Do not ask about dot spacing, light, speed, repel size or anything else in the settings table up front. After the first build, tell them in one or two lines what they can now ask for in plain words (finer or coarser dots, lighter or heavier, slower or still, a 45 degree grid, a stronger or weaker push, a different starting angle), and mention the Repel size slider on the page.
Then say back, in one line, what you are about to build ("Bust, then Robot, black on white, for a website: building now"), and build.
One command
This skill is written for any coding agent that can read files and run a shell command. Nothing in it depends on
a particular model or product; <this skill's folder> below is wherever this file lives.
python <this skill's folder>/scripts/dither_morph.py keyboard.glb mouse.glb --open
That is the whole job. It needs only Python 3.9+. On first run it creates its own environment in
~/.dither-morph/venv and installs numpy, scipy, trimesh and pillow there (about a minute, needs internet once);
nothing is installed system-wide. Then it builds the page into ./dither-morph/<names>.html, an embed folder
<names>_embed/ beside it (see Put it in their site), check pictures if Chrome or Edge is installed, and prints
the paths. --open opens the page in the browser.
- Button labels come from the file names; write
Label=pathto choose them. Order given = order of the buttons. - One model is fine (hover only, no buttons). Several models morph into each other.
- No models yet?
dither_morph.py --demo --openbuilds a stand-in keyboard and mouse so the user can see the effect. - FBX and .blend are not read; ask the user to export GLB, or convert with Blender if it is installed.
Options (all optional):
| option | what it does |
|---|---|
--out page.html | where to write the page. |
--points 150000 | points per model in the hidden cloud (about 16 KB per 1000 points per model, so 2.4 MB each). 60000 for a public web page or phones; raise only if the dot spacing goes below about 3 px. |
--palette ink | ink (black on white, default), sepia (black on warm paper), paper (light on dark), pink, teal, night, amber. |
--background --ramp --accent | own colours. Ramp = dot colours from shadow to light, 1 to 8; one colour is the classic halftone. --background transparent to sit on a page's own background. |
--zup Label … | models whose file is Z-up (most STL and CAD exports; GLB is Y-up and needs nothing). all for every one. |
--config '{"pitch":4,"angle":45}' | any viewer setting (table below) baked in as the default. |
--no-shots | skip the check pictures. |
Then look at it
Read the check pictures (<page>_shots/: each model at rest, two with the cursor pushed in, three stages of the
change) before telling the user it is done. Fix what is off, rebuild, and say what you could not judge: stills
cannot show how the motion feels, so the user has to try the page.
- Tone. There should be real white in the lit areas, near-solid colour in the deepest shadow, and a full run of
dot sizes between. Too heavy (a dark-textured model): raise
gamma. Too faint: lowergammaor raisecontrast. Movelightto put the shadow where it describes the form. - Readable? Detail smaller than two or three dots is lost; that is the nature of halftone. Lower
pitchfor finer dots, or raisescale. A thin or flat model sits small, because every model is fitted inside the same sphere so that morphs stay centred; raisescale. - Edges should thin out to small dots, not end in a hard line (
rim). - Upright and facing well? Wrong way up means
--zup(or its absence). A poor first angle: setyawandtilt. - Mid-change should be a soft cloud of mixed dot sizes with both shapes faintly present, not a blank frame.
Settings
Every setting can be tried live in the address bar (page.html?pitch=4&hoverPush=0.6&spin=0) and then baked in
with --config.
| setting | default | meaning |
|---|---|---|
pitch | 5 | distance between dots in screen pixels. The main "how fine" control. |
maxDot | 0.62 | radius of the biggest dot as a share of the pitch: 0.5 dots just touch, 0.62 they merge with small gaps, 0.71 solid. |
minDot | 0.03 | tone kept in the lightest parts, so lit surfaces keep faint dots. 0 lets highlights go fully blank. |
gamma | 1.5 | tone curve. Higher = lighter overall, only shadows stay heavy. |
angle | 0 | grid angle in degrees; 45 is the classic print screen. |
invert | auto | on dark backgrounds the lit areas get the big dots. |
scale | 0.9 | model size against the shorter side of the page. |
contrast, rim, light | 1.15, auto, upper left | tone; edge fade (+ lighter, − darker); light direction as x,y,z. |
spin, tilt, yaw | 0.14, 0.38, 0.6 | turntable speed, look-down angle, starting turn (radians). Drag always turns it. |
hoverRadius, hoverPush | 0.09, 0.4 | size of the pushed patch (share of the shorter side); how far dots move apart. The page has a Repel size slider that shows its number, so the user can find the value they like. |
hoverTint, hoverTrail | 0, 0.5 | share of pushed dots in the accent colour; seconds the push lingers behind the cursor. |
morphSeconds, morphStagger, morphSwirl, morphSpin | 2.6, 0.6, 0.4, 0.9 | length of a change; how spread out the departures are; how curved the paths; extra turn on the way. |
smooth | 0.07 | seconds over which tone is blended; this stops dots flickering while the model turns. 0 = off. |
autoCycle | 0 | seconds between automatic changes (0 = only on click). |
ui, tune, start | true, auto, 0 | show the model buttons; show the Repel size slider (by default only on the standalone page, where it is a tuning aid); which model shows first. |
Put it in their site
Making the page is half the job. The object is interactive code, not a video: it cannot be exported and dropped in like a picture, so someone has to wire it into the site. That someone is you. Do not hand the user a file and a paragraph of instructions if you can reach their site's files.
Every build writes two things:
<name>.html: a standalone page with everything inside it. For looking at the result, and for sites that can only take an iframe.<name>_embed/: the piece that goes inside an existing page, with no frame.dither-morph.js(the viewer, 33 KB, the same for every build),<name>.dm(the models), andexample.html(a plain page showing it in place).
In a page it is one script and one tag, sized with CSS like an image:
<script src="/dither-morph/dither-morph.js"></script>
<dither-morph src="/dither-morph/objects.dm" style="height: 70vh" background="transparent"></dither-morph>
Every setting from the table above works as an attribute, in any spelling (hover-radius, hoverRadius,
hoverradius): pitch="4" angle="45" ui="false" auto-cycle="6" start="1".
Steps
-
Find the site and what it is built with. If the working folder is a website, read it:
package.json(next, react, vite, astro, svelte, vue, nuxt), a bareindex.html, a Hugo or Jekyll config, a WordPress theme. If there is no site here, ask where it lives and what it is made with. Ask where on which page the object should go if they have not said. -
Build light.
--points 60000for anything public (about 0.7 MB per model). -
Copy
dither-morph.jsand the.dmfile into the folder the site serves untouched:site put them in address in the page Next.js, Vite, React, Astro, Vue, Nuxt public/dither-morph//dither-morph/...SvelteKit, Hugo static/dither-morph//dither-morph/...Jekyll, plain HTML assets/dither-morph/or beside the pagerelative path -
Add it to the page, in the way that stack expects:
-
Plain HTML, Astro, Hugo, Jekyll, Svelte, Vue: the two lines above, as they are. (Vue may warn about an unknown element;
compilerOptions.isCustomElement = tag => tag === "dither-morph"silences it.) -
React, Next.js: a small client component. The script touches the browser, so load it after mount.
"use client"; import { useEffect } from "react"; export default function DitherMorph({ src, ...props }) { useEffect(() => { if (customElements.get("dither-morph")) return; const s = document.createElement("script"); s.src = "/dither-morph/dither-morph.js"; document.head.appendChild(s); }, []); return <dither-morph src={src} background="transparent" style={{ height: "70vh" }} {...props} />; }In TypeScript add once:
declare namespace JSX { interface IntrinsicElements { "dither-morph": any } }(with React 19:declare module "react" { namespace JSX { interface IntrinsicElements { "dither-morph": any } } }). -
Site builders with no file access (Webflow, Framer, Wix, Squarespace, WordPress.com, Notion sites): the files have to live somewhere else. Put the standalone
<name>.htmlon any static host (GitHub Pages, Netlify, Cloudflare Pages, the user's own server) and give them an embed block:<iframe src="https://their-host/objects.html?ui=false" style="border:0;width:100%;height:70vh" loading="lazy"></iframe>. Use the frame here rather than the tag: the tag fetches the.dmfile, and a browser only allows that from another address if that host sends the right permission headers, which is one more thing to go wrong. Hosting and publishing are the user's accounts: tell them what to upload, do not do it for them unasked.
-
-
Make it sit well. Give it a height (it has no natural one; the default is 480 px).
background="transparent"lets the page's own background show; on a dark page also setramp="#f2efe6"(dot colour) andinvert="true". The buttons are inside the element;ui="false"removes them when the page has its own controls. -
Wire it to the page if asked. The element has
show("Label" or number),next(),prev(),labelsandcurrent, and sendsreadyandchangeevents. Their own buttons:document.querySelector("dither-morph").show("Robot"). A favourite: change model as sections scroll into view.const dm = document.querySelector("dither-morph"); const seen = new IntersectionObserver(es => es.forEach(e => e.isIntersecting && dm.show(e.target.dataset.model)), { threshold: 0.6 }); document.querySelectorAll("[data-model]").forEach(el => seen.observe(el));From outside an iframe:
frame.contentWindow.postMessage({ ditherMorph: "show", model: "Robot" }, "*")(also"next","prev"). -
See it working in the site, not just on its own. Run their dev server or open the built page, and look. The usual failure is a wrong path: the object area stays empty and the browser console shows a 404 for the
.dmfile. Opening a page straight from disk (file://) cannot load the.dmfile either; that is expected, use a local server. If a host refuses the.dmending, rename the file (.binis fine; only thesrcmatters).
Leave their site's git alone: make the change, show it, and let them commit and deploy unless they ask you to.
It pauses when scrolled out of view and calms down for people who ask their system for reduced motion. One or two on a page is fine; many at once will cost frame rate on phones.
How it works (so you can change it sensibly)
scripts/build.pyscatters points over each surface, thins them to an even spread, and stores position, normal and surface brightness (texture, vertex colour or material colour) per point, embedded in the page.- Every model has the same number of points in the same spatial order (repeated halving along x, y, z). Point i is in the matching region of every model, so a change looks like the shape rearranging itself and not like a swarm. Consequence: models that should morph into each other must go through one build. To add a model later, rebuild with the full list.
assets/dither-morph.jsis the viewer, written as a<dither-morph>element; the standalone page (assets/viewer_template.html) is a thin shell with that script and the models pasted in, so both outputs run the same code. It works in steps each frame. The point cloud is drawn, lit, into a small hidden tone picture and blended over a few frames (a single frame is grainy, and that grain is what makes dots flicker). Then, at full screen resolution, every dot of the grid reads the tone under its home position and is drawn as a smooth round dot of matching size; where the cloud only partly covers a dot it is smaller.- The hover acts on the dots: each is shifted away from the cursor by a soft lens with a short fading trail and carries its tone with it, so the patch looks magnified. The morph acts on the cloud underneath.
scripts/shots.pytakes the check pictures using test hooks in the page:?freeze=1.5(fixed moment),&mouse=0.5,0.5(cursor at that fraction of the page),&morph=1,0.5(half way to model 1),?sim=3&sweep=0.3,0.5,0.6,0.5(run the real loop 3 s with the cursor gliding, then hold).
Limits to be honest about
- Dots stay on the screen grid; during a change they resize in place while the shape moves beneath.
- Colour comes from the ramp, not from the model: textures only contribute light and dark.
- Models with separate inner parts or open, single-sided surfaces can show their insides.
- Needs WebGL2 (every current browser). It makes a live page, not a video or GIF.