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

Neon Combo · How it works & code

Neon effect is built from multiple layers of filters — the outermost layer is a broad, semi-transparent colored glow (blurred drop-shadow), followed by...

Runtime logic

Visiting `/filters/neon-combo`, DemoHost lazy-loads `demos/kits/kit-filters.js` (registry `mod: 'kit-filters'`) and calls `mount(host, { variant: 'neon-combo' })`. mount resolves the variant to family `neon-combo`; `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°); 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.fillRect() — Fills a rectangle; ctx.save() — Saves the drawing state (transform, styles, clip); ctx.fillText() — Draws filled text; ctx.restore() — Restores the saved drawing state; 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.fill() — Fills the current path; ctx.stroke() — Strokes the current path; ctx.rect() — Adds a rectangle to the path; ctx.clip() — Turns the current path into the clipping region; ctx.translate() — Translates the coordinate system

Source code

frontend/src/demos/kits/kit-filters.js: FAM.neon-combo (L275-L291)

Code walkthrough

L275-291: Calls the factory `fFam()` to produce the full definition (spec + doc + build) from the options below. L275-275: Title shown in the info and control panels: “Neon Combo”. L275-275: Range/default of the count slider. L275-275: Extra demo-specific slider/toggle: Emission intensity. L275-275: Range/default of the size slider. L275-275: Default main colour. L275-275: Hide sample photo. L276-276: Help text of the count parameter. L276-276: Help text of the extra parameter. L276-276: Help text of the size parameter. L277-277: Preset buttons: name → parameter overrides (5). L278-278: Body of the “Notes” section. L279-279: Main formula of the “Formula” section. L279-279: Second formula line. L280-291: Per-frame draw function: draws with Canvas 2D `fillRect`, `save`, `fillText`, `restore`; math via `Math.min`, `Math.max`, `Math.sin`, `Math.pow`, `Math.abs`, `Math.round`; returns readouts `mode`, `cell` to the info panel.

Principles

Optical zone i: drop-shadow (0) (4) · 3ⁱ · Intensity) px colour), i = 0, 1, 2 Lantern colour = white mixed with main colour Combining neon: The effect of neon lights is that several layers of filters are folded -- the outermost is wide, Trans FIFT pulled colour lumber (drop-shadow in Superior) with smaller lum Subsequently close to the accept Each of the white lamps in Foreign Affairs. Traditionally, it's like exposure to bad neon lights.

Open the interactive demo · GitHub