Scene and gravity
Objects inside one scene share a canvas and can react to each other. Pick which object is the center of gravity.
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 scene works
A scene is a block element that owns one canvas covering its own box. Its children are placed with ordinary CSS, and each object renders centered on its layout box. Interactions may move an object visually without touching the layout, so your page never reflows.
Gravity
Orbiters take concentric rings: they are sorted by how far the layout puts them from the center, the nearest ring keeps clear of the center, the farthest sits at the farthest rest distance, and the rings in between are spread evenly. A ring turns at a speed that falls with its radius to the power 1.5, so the outer ring sets the pace and inner rings pass it, the way planets do.
| Attribute | Type | Default | Range | Description |
|---|---|---|---|---|
gravity | keyword | orbit | center, orbit, fall, none | On an object: its role. Exactly one center; extra centers orbit. Orbiters sit on rings, one each, farther rings turning slower. |
gravity-strength | number | 0.6 | 0 to 1 | On the scene: orbital speed and pull. At 1 the outer ring turns once every 21 seconds. |
gravity-gap | number | 24 | 0 to 200 | On a falling object: distance it keeps from the center, in px. |
License
MIT. Use it anywhere, credit appreciated.