Smoke Column · How it works & code
Smoke particles rise from the bottom source, growing larger and more transparent with height, spreading outward according to the diffusion angle; a pointer simulates wind pushing the smoke off course.
Runtime logic
Visiting `/particles-fx/smoke-col`, DemoHost lazy-loads `demos/kits/kit-particles.js` (registry `mod: 'kit-particles'`) and calls `mount(host, { variant: 'smoke-col' })`. mount resolves the variant to family `smoke-col`; `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.fill() — Fills the current path; ctx.beginPath() — Starts a new path; ctx.moveTo() — Moves the pen without drawing; ctx.arcTo() — Adds an arc using tangent lines; ctx.closePath() — Closes the current sub-path; ctx.stroke() — Strokes 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.smoke-col (L137-L145)
Code walkthrough
L137-145: Calls the factory `pFam()` to produce the full definition (spec + doc + build) from the options below. L137-137: Title shown in the info and control panels: “Smoke Column”. L137-137: Range/default of the size slider: Smoke Blob Size. L137-137: Range/default of the count slider: Particle Count. L138-138: Extra demo-specific slider/toggle: Diffusion Angle. L138-138: Default main colour. L138-138: Preset buttons: name → parameter overrides (4). L139-139: Body of the “Notes” section. L139-139: Main formula of the “Formula” section. L139-139: Second formula line. L140-145: Per-frame draw function: draws with Canvas 2D `fill`; math via `Math.sin`.
Principles
Age a = true (seed + 0.2t) Radius = Size · (0.3 + a), transparency = (1 − a) · 0.3 Smoke column: The smoke is rising from the bottom, increasing with height, Transparent and spread across the sides by a proliferation angle; the pointer blows the smoke like the wind. The location of each particle here is numbered i Random Feeds + Time t + 指针位置」直接算出来,所以拖动滑条会立刻生效。