Particle sculpture
A web component, <particle-sculpture>, that draws two shapes out of the same particles and morphs between them. It is one JavaScript file with three.js built in, plus small point files (.pts) for the shapes. No build step and no framework are needed; it works in plain HTML and inside React, Vue, Astro, Next.js and the like.
Everything you need is in this skill's assets/ folder:
assets/particle-sculpture.js: the element (about 0.5 MB, three.js included).assets/library/<name>.pts: 20 ready shapes, 20,000 points each (about 120 KB each).assets/library/manifest.json: suggested pairs with palettes, and the credits three shapes need.assets/example.htmlandassets/sculpture.json: a complete working page. Copy from them.assets/LICENSES.txt: the MIT licence of three.js. It must travel withparticle-sculpture.js.
Add one to a site
- Pick two shapes (see "Shapes") and copy these into one folder the site serves as static files, for example
public/sculpture/:particle-sculpture.js,LICENSES.txtand the two.ptsfiles. Copy the files as they are. Do not import the script through a bundler: it is already bundled, and it fetches its other files at run time. - Write
sculpture.jsonin the same folder. Onlysubjectsis required:
{
"subjects": ["seed.pts", "tree.pts"],
"direction": "down",
"palette": ["#efeadc", "#7bd389", "#efeadc", "#d9a441"],
"background": "#0b0b0c",
"glyphs": ["triangle"],
"fieldCount": 160
}
- Put the element in the page:
<script type="module" src="/sculpture/particle-sculpture.js"></script>
<particle-sculpture config="/sculpture/sculpture.json" style="height: 300vh"></particle-sculpture>
Paths in subjects and poster are relative to the config file. The src and config paths themselves follow normal URL rules: root-absolute (/sculpture/...) when the site is served from the domain root, relative when it may live in a subfolder. The full list of settings is in references/config.md; read it before setting anything beyond the example above.
A page can hold several sculptures. Load the script once, and give each element its own config file under any name (hero.json, network.json). Each one is a separate WebGL canvas, so keep it to a few per page.
Choose how it morphs
"direction": "down"follows the page scroll. Give the element a height well above the viewport (300vhis a good start); the canvas pins itself while the page scrolls through the element. Pinning usesposition: sticky, which silently stops working when any ancestor hasoverflow: hidden,autoorscroll. Check the ancestors; this is the most common reason a scroll sculpture does not stay in place."direction": "side"shows two round arrow buttons at the bottom centre and follows a horizontal drag and the arrow keys. Use it when the sculpture sits in a normal-height section. Give the element a fixed height such as70vh. The buttons are white on translucent black and cannot be restyled from the page, so they suit dark backgrounds; on a light background driveprogressfrom your own buttons instead.- To drive it yourself (a button, a timeline, a scroll library), set the element's
progressproperty to a number from 0 to 1. Thereadypromise exists only once the script has loaded, so wait for the element first:
await customElements.whenDefined('particle-sculpture');
const el = document.querySelector('particle-sculpture');
const ok = await el.ready; // false when the sculpture could not start
Lay it out
- Size and position. The shape is always centred in the element and scaled to it. To put the shape on the right with a headline on the left, make the element narrower and move the element (a grid column, or
margin-left: 40%); the pinned canvas takes the element's width, not the viewport's. On narrow screens let it go full width and put the copy above or over a solid backing. - Copy that stays during a scroll morph. The element has no slot for content. Put the copy in a sibling that covers the element (
position: absolute; inset: 0) and inside it a block withposition: sticky; top: 0; height: 100vh, so the headline stays for the whole morph.assets/example.htmldoes exactly this. Give the overlaypointer-events: none(andautoon its links and buttons) so the pointer still reaches the particles. - Text and particles. Keep text off the middle of the shape or give it a solid backing. The particles are bright, and text over them is hard to read.
- Name it for assistive technology. The canvas has no label of its own. Put
role="img"and anaria-labeldescribing the two shapes on the element when it carries meaning, oraria-hidden="true"when it is decoration. Leave the role off a side-mode element, which is focusable and has real buttons inside.
Shapes
The 20 library shapes: brain, lightbulb, seed, tree, car, trophy, dna, figure, cube, skyline, globe, network, heart, home, key, shield, book, cap, bubble, soundwave. Any two can be paired. manifest.json lists ten pairs chosen for meaning (thinking → idea, start → growth, access → security and so on) with a palette each; prefer one of them when the user has no shapes in mind. book, cube and car read less clearly than the rest, so avoid them for a hero unless asked.
brain, lightbulb and car come from CC BY 4.0 models. If the page uses one, the credit in manifest.json (title, author, source, licence link, changes) has to be shown somewhere on the published site, such as the footer or a credits page. The element does not show it. Add it, and tell the user you did and why.
For the user's own logo, image or 3D model, read references/custom-shapes.md. In short: the free studio at https://particles.shirlaw.app turns an upload into the files with no install, and the open-source project bakes them from the command line.
Make it fit the site
- Take
palette(one to four colours) andbackgroundfrom the site's own colours rather than keeping the defaults. Each entry gets an equal share of the particles, so repeat a colour to weight it: neutral, accent, neutral gives the accent a third. On a light background use darker particle colours; glyphs are thin outlines, and pale colours vanish on white. - Set
backgroundto the colour of the section behind the element so the canvas has no visible edge. colorGrouping(0 to 1, default 0.7) makes neighbouring particles share a colour so the palette falls in bands; 0 is confetti.fieldCount(0 to 2000) adds glyphs drifting behind and in front of the shape; 100 to 300 gives depth without clutter.
What to check before you finish
- Open the page and confirm the shape draws and morphs. A blank area almost always means a wrong path: the browser's network tab will show a 404 for
sculpture.jsonor a.ptsfile. The page must be served over http(s); opening the file directly from disk blocks the fetches. - The element needs WebGL 2. Where it is missing, or a file fails to load,
readyresolvesfalseand the element shows theposterimage from the config if there is one, and nothing otherwise. It keeps its height either way, so a 300vh scroll hero becomes a tall empty stretch. Handle that: whenreadyisfalse, add a class that collapses the element to a normal height, asassets/example.htmldoes. If you can take a screenshot of the working sculpture, also save it as theposterwith aposterAlt; if you cannot, say so and leave the poster out rather than pointing at a file that does not exist. - Phones and narrow viewports draw at most 8,000 particles automatically. With
prefers-reduced-motionthe element crossfades instead of flying the particles. You do not need to add either. - In a framework that renders on the server, load the script on the client only (a
<script type="module">tag, or the framework's client-side script component). The custom element tag itself is safe to render on the server. - Under a Content Security Policy, the element needs
script-srcfor its file,connect-srcforsculpture.jsonand the.ptsfiles, andimg-srcfor the poster. It needs no inline styles.
Limits worth telling the user
It has been tested in Chromium only, and frame rate has not been measured on real phones. Say so if the user asks about browser support or performance rather than guessing, and suggest lowering count if a device struggles.