加载应用…
云澜 Clyune Clyune Component Gallery · 中文

Quantum Jitter · How it works & code

Nucleus at center, electrons move along tilted elliptical orbits; greater electron cloud diffusion means more dispersed 'probability cloud' particles, illustrating quantum uncertainty.

Runtime logic

Visiting `/particles-fx/quantum`, DemoHost lazy-loads `demos/kits/kit-particles.js` (registry `mod: 'kit-particles'`) and calls `mount(host, { variant: 'quantum' })`. mount resolves the variant to family `quantum`; `withControls` builds the control panel (6 presets + sliders). `createCanvasStage` creates the `<canvas>` (HiDPI ≤ 2×, ResizeObserver) and 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; 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

Dependencies

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; createCanvasStage — Shared Canvas 2D stage: canvas + info panel, HiDPI, one rAF loop, pointer state, idle auto-pointer; hueOf — Hue of a colour (0–360°); clamp — Clamps a value to a range; TAU — Constant 2π; fmt — Number formatting (fixed decimals); F — Formula block HTML; S.clear — Clears with the background colour (translucent = trails); S.onFrame — Registers a per-frame callback; its return value feeds the info panel; ctx.beginPath() — Starts a new path; ctx.ellipse() — Adds an elliptical arc; ctx.stroke() — Strokes the current path; ctx.moveTo() — Moves the pen without drawing; ctx.arcTo() — Adds an arc using tangent lines; ctx.closePath() — Closes the current sub-path; ctx.fill() — Fills the current path; ctx.fillRect() — Fills a rectangle; ctx.arc() — Adds a circular arc (center, radius, start/end angle); ctx.save() — Saves the drawing state (transform, styles, clip); ctx.rect() — Adds a rectangle to the path; ctx.clip() — Turns the current path into the clipping region; ctx.restore() — Restores the saved drawing state

Source code

frontend/src/demos/kits/kit-particles.js: FAM.quantum (L335-L348)

Code walkthrough

L335-348: Calls the factory `pFam()` to produce the full definition (spec + doc + build) from the options below. L335-335: Title shown in the info and control panels: “Atomic Orbital”. L335-335: Range/default of the size slider: Electron Size. L335-335: Range/default of the count slider: orbits. L336-336: Extra demo-specific slider/toggle: Electron Cloud Diffusion. L336-336: Default main colour. L336-336: Preset buttons: name → parameter overrides (4). L337-337: Body of the “Notes” section. L337-337: Main formula of the “Formula” section. L337-337: Second formula line. L338-348: Per-frame draw function: draws with Canvas 2D `beginPath`, `ellipse`, `stroke`; math via `Math.min`, `Math.cos`, `Math.sin`; returns readouts `n` to the info panel.

Principles

Or Within orbit i: Inclination = i · π / n,x = a · cos θ,y = b · sin θ Cloud Particle = Electronic Position + Spread · Goss random offset Atomic orbits: Atoms are at the centre, electrons move along tilted elliptical orbits; the greater the diffusion of electron clouds, the more dispersed the "probability cloud" particles around each electron reflect the uncertainty of quantum. The location of each particle here is numbered i Random Feeds + Time t + 指针位置」直接算出来,所以拖动滑条会立刻生效。

Open the interactive demo · GitHub