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

Glowing Edge · How it works & code

Draw only the outline of the shape and add a blurred shadow (drop-shadow / text-shadow) to it in the same color — that's how you get...

Runtime logic

Visiting `/filters/glow-edge`, DemoHost lazy-loads `demos/kits/kit-filters.js` (registry `mod: 'kit-filters'`) and calls `mount(host, { variant: 'glow-edge' })`. mount resolves the variant to family `glow-edge`; `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.save() — Saves the drawing state (transform, styles, clip); ctx.stroke() — Strokes the current path; ctx.restore() — Restores the saved drawing state; ctx.beginPath() — Starts a new path; ctx.arc() — Adds a circular arc (center, radius, start/end angle); ctx.fill() — Fills 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.fillRect() — Fills a rectangle; ctx.rect() — Adds a rectangle to the path; ctx.clip() — Turns the current path into the clipping region; ctx.translate() — Translates the coordinate system; ctx.lineTo() — Adds a straight line to a point

Source code

frontend/src/demos/kits/kit-filters.js: FAM.glow-edge (L353-L364)

Code walkthrough

L353-364: Calls the factory `fFam()` to produce the full definition (spec + doc + build) from the options below. L353-353: Title shown in the info and control panels: “Glowing Edge”. L353-353: Range/default of the count slider. L353-353: Extra demo-specific slider/toggle: Glow Radius. L353-353: Range/default of the size slider. L353-353: Default main colour. L353-353: Hide sample photo. L354-354: Help text of the count parameter. L354-354: Help text of the extra parameter. L354-354: Help text of the size parameter. L355-355: Preset buttons: name → parameter overrides (5). L356-356: Body of the “Notes” section. L357-357: Main formula of the “Formula” section. L357-357: Second formula line. L358-364: Per-frame draw function: draws with Canvas 2D `save`, `stroke`, `restore`, `beginPath`, `arc`, `fill`; math via `Math.cos`, `Math.sin`; returns readouts `mode`, `cell` to the info panel.

Principles

Optical = drop-shadow (0 r colour) superseding drop-shadow (0 r) / 3 Colours) Flow position = on profile (time) · 0.25) Mod 1 Lighting side: only a con SCOSE line is painted, and the contours are shaded with the same colour (drop-shadow) / text-shadow) gets a circle of light. Add two layers, The light will be more full. A bright spot runs along the contours, simulates the flow of light.

Open the interactive demo · GitHub