Ring
A ring of pixels spreads from a point and dies out.
- Drawn with
- GLSL + CPU
- Chain
- constant → pixelate → ordered → ring → palette
- Code
- @forgeron/shaders: ringMeta, ringGlsl, ringCpu
/01 → What it is
- The radius grows with the age; a cell near it is drawn where the Bayer threshold is under its closeness times the life left.
- One tone per slice of its life: bright at birth, dim at the end. The Feedback example.
- Both sides: GLSL and CPU, with the same result. A cell pass.
- CPU against GLSL: tolerance 1 % of pixels (measured 0).
/02 → In the examples
| Example | Chain |
|---|---|
| Feedback | constant → pixelate → ordered → ring → palette |
/03 → Versions
- /01 Live
every setting, on "ring" - /02 Wide
width 4, life 1.5
/04 → Use it
{
"type": "ring",
"cx": 0.5,
"cy": 0.5,
"speed": 0.45,
"width": 2.5,
"start": 0,
"life": 1,
"repeat": 0,
"tones": [
3,
2,
1
],
"matrix": 8
}import { ringMeta, ringGlsl, ringCpu } from "@forgeron/shaders";
// ringMeta: description and params schema (validation, the editor)
// ringGlsl: the GPU side, for bindChain then glPipeline
// ringCpu: the CPU side, for bindChain then runCpu{
"$schema": "https://shaders.forgeron.sh/schema/preset.v1.json",
"version": 1,
"name": "ring",
"source": {
"type": "constant",
"value": 0
},
"passes": [
{
"type": "pixelate",
"size": 4
},
{
"type": "ordered",
"matrix": 8,
"centered": true,
"origin": "top",
"steps": [
[
0,
1
]
]
},
{
"type": "ring",
"cx": 0.5,
"cy": 0.5,
"speed": 0.45,
"width": 2.5,
"start": 0,
"life": 1,
"repeat": 3,
"tones": [
2,
1
],
"matrix": 8
},
{
"type": "palette",
"tones": [
{
"var": "--bg",
"fallback": "#0a0a0a"
},
{
"var": "--ink",
"fallback": "#ededed"
},
{
"var": "--accent",
"fallback": "#ff4f1f"
}
],
"transparent": []
}
]
}import { builtInPresets } from "@forgeron/shaders";
import { mountPreset } from "@forgeron/shaders/dom";
// WebGL2: every step has GLSL. Validated first.
const handle = mountPreset(canvas, builtInPresets()["ring"]);
// later: handle?.destroy();import { builtInPresets, chainOf, runCpu, toRgba } from "@forgeron/shaders";
// The CPU side of every step: RGBA bytes for a PNG, or tone paths for an SVG (toSvgPath).
const rgba = toRgba(runCpu(chainOf(builtInPresets()["ring"]), 320, 200, { time: 1.7 }));API → Options
| Option | Type | Default | Description |
|---|---|---|---|
cx | number | 0.5 | Centre, left to right. |
cy | number | 0.5 | Centre, top to bottom. |
speed | number | 0.45 | Width per second. |
width | number | 2.5 | Half thickness. |
start | number | 0 | Second it starts at. |
life | number | 1 | Seconds it lives. |
repeat | number | 0 | Seconds between rings. |
tones | number[] | [3,2,1] | Tone per slice of its life. |
matrix | 2 | 4 | 8 | 8 | Bayer matrix. |