Universe
One element fills its box with a cloud of shapes in three dimensions. Spin it, drag it, set the focal plane, turn on collisions.
Add the script once, then use the tags anywhere.
<script type="module" src="https://mmaxence.github.io/solids/solids.js"></script>
Or copy the library into your project: download solids.js from the repo and serve it yourself. No build step, no other files.
How a universe works
<sd-universe> is a scene. On first connect it creates its children from a seeded random sequence: a shape, a spot in a unit ball chosen to keep its distance from the others, a size, a color, and an animation with its own speed and phase. They are ordinary objects in the light DOM with a data-pos, so Copy code gives you markup you can paste and edit; a universe that already has children keeps them.
Every frame the universe moves its shapes and places them through a camera. Shapes drift and wobble on their own paths and turn back at the edge of the ball; with collide they bounce off each other. The camera sits at a distance set by perspective and turns with the tokens in camera: spin on its own, drag with the pointer or a swipe (with inertia), pointer as a tilt toward the cursor.
Depth comes from the camera: near shapes draw larger and on top, far ones smaller and behind. Each shape gets the defocus effect with a radius of depth times its distance from the focus plane, times 14 px, and shapes behind the plane are dimmed. Under reduced motion nothing moves on its own; drag and the pointer tilt still work.
Options
| Attribute | Type | Default | Range | Description |
|---|---|---|---|---|
count | number | 24 | 0 to 120 | How many shapes. Changing it regenerates the children. |
seed | number | 1 | any integer | The same seed always gives the same universe: positions, sizes, colors and motion. |
collide | boolean | absent | present or absent | Shapes bounce off each other and keep their speed. |
camera | list | spin drag pointer | spin, drag, pointer | How the view moves: spin turns on its own, drag or swipe rotates it with inertia, pointer tilts it toward the cursor. none for a fixed view. |
speed | number | 1 | 0 to 4 | How fast the camera spins. 1 is one turn every 90 seconds. |
drift | number | 0.5 | 0 to 1 | How much the free shapes float about. 0 holds them in place. |
perspective | number | 0.5 | 0.05 to 1 | How strongly near shapes grow and far ones shrink. Higher brings the camera closer. |
depth | number | 0.5 | 0 to 1 | Strength of the depth of field. 0 keeps every shape sharp. |
focus | number | 0 | -1 to 1 | The focal plane, from the back (-1) to the front (1), in camera space. |
shapes | list | every object | object tags | Space separated tags to draw from, for example sd-orb sd-ring. Unknown tags are skipped. |
palette | list | six P3 colors | any CSS colors | Space separated colors to pick from. |
License
MIT. Use it anywhere, credit appreciated.