Ring Point Cloud · How it works & code
Saturn's rings are made of countless ice particles, each orbiting Saturn like a small moon.
Runtime logic
Visiting `/threejs/ringcloud`, DemoHost lazy-loads `demos/kits/kit-three.js` (registry `mod: 'kit-three'`) and calls `mount(host, { variant: 'ringcloud' })`. mount resolves the variant to family `ringcloud`; `withControls` builds the control panel (6 presets + sliders). `createThreeStage` sets up WebGLRenderer, Scene, PerspectiveCamera and OrbitControls, plus the info panel. The family’s `build(S)` initialises state and returns the per-frame callback. Every `requestAnimationFrame`: read controls, advance a speed-scaled clock (dt ≤ 50 ms), run the frame callback; returned readouts go to the info panel. Changing parameters: colour/speed/size apply live; structural ones remount; leaving the page cancels rAF, removes listeners and frees resources.
Environment
Canvas 2D: 2D canvas drawing; WebGL (three.js): WebGL through three.js WebGLRenderer; requestAnimationFrame: Display-synced animation loop; ResizeObserver: Canvas follows container size; Pointer Events: Unified mouse/touch/pen events; devicePixelRatio: Crisp HiDPI rendering (capped at 2×) · react 18.3.1, react-router-dom 6.30.6, vite 5.4.21, three 0.170.0
Dependencies
three 0.170.0, three/addons/controls/OrbitControls.js 0.170.0, react 18.3.1
Imported APIs
withControls — Wraps the demo in the shared control panel (presets, sliders, reset); hot-updates or remounts on change; paramsFromSpec — Turns the spec (colour/speed/size/count/extras) into control-panel parameter definitions; createThreeStage — Shared three.js stage: WebGLRenderer, scene, perspective camera, OrbitControls, auto framing and render loop; addLights — Adds ambient + key + fill lights; THREE — three.js namespace; fmt — Number formatting (fixed decimals); F — Formula block HTML; S.get — Reads current control values; S.onFrame — Registers a per-frame callback; its return value feeds the info panel; THREE.BufferGeometry — Custom vertex geometry; THREE.BufferAttribute — Typed vertex attribute (positions/colours); THREE.PointsMaterial — Points material; THREE.Points — Point cloud; THREE.Mesh — Mesh (geometry + material); THREE.SphereGeometry — Sphere geometry; THREE.MeshStandardMaterial — PBR standard material
Source code
frontend/src/demos/kits/kit-three.js: FAM.ringcloud (L256-L286)
Code walkthrough
L257-257: Control definitions (colour/speed/size/count/extras): Color, Orbital Speed, Point size, Point Count (×100), Ring Thickness. L258-258: Preset buttons: name → parameter overrides (6). L259-259: 3D framing radius. L260-268: Info-panel content: live rows(v), formula, notes, params, steps. L269-285: Init function: sets up state and returns the per-frame callback: creates three.js objects `BufferGeometry`, `BufferAttribute`, `PointsMaterial`, `Points`, `Mesh`, `SphereGeometry` …; math via `Math.max`, `Math.min`, `Math.round`, `Math.random`, `Math.cos`, `Math.sin`; returns readouts `n`, `wIn`, `wOut`, `ratio`, `th`, `ps` to the info panel.
Principles
ω(r) = ω₀ · r^(−3 / 2 ( Aspects Nonetheless Lawyers) 129/52 25 Internal ratio = 1.6 / 0.9)^1.5 ≈ 2.37 土星环由无数冰块组成,每块都像小卫星一样绕土星公转。离得越近转得越快(ω ∝ r^−1.5),So the ring's inside“Overtake”Outside, it's called Swap 。 Each frame of the program adds a different angle to each point by its radius, and the original flat point is slowly pulled out of the spiral texture.