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.

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

AttributeTypeDefaultRangeDescription
countnumber240 to 120How many shapes. Changing it regenerates the children.
seednumber1any integerThe same seed always gives the same universe: positions, sizes, colors and motion.
collidebooleanabsentpresent or absentShapes bounce off each other and keep their speed.
cameralistspin drag pointerspin, drag, pointerHow 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.
speednumber10 to 4How fast the camera spins. 1 is one turn every 90 seconds.
driftnumber0.50 to 1How much the free shapes float about. 0 holds them in place.
perspectivenumber0.50.05 to 1How strongly near shapes grow and far ones shrink. Higher brings the camera closer.
depthnumber0.50 to 1Strength of the depth of field. 0 keeps every shape sharp.
focusnumber0-1 to 1The focal plane, from the back (-1) to the front (1), in camera space.
shapeslistevery objectobject tagsSpace separated tags to draw from, for example sd-orb sd-ring. Unknown tags are skipped.
palettelistsix P3 colorsany CSS colorsSpace separated colors to pick from.

License

MIT. Use it anywhere, credit appreciated.