@uxfront/scene 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -13
- package/dist/experience.d.ts +8 -5
- package/dist/experience.js +30 -41
- package/dist/formations/index.d.ts +7 -2
- package/dist/formations/index.js +7 -2
- package/dist/formations/plates/art.d.ts +4 -24
- package/dist/formations/plates/art.js +17 -81
- package/dist/formations/plates/shader.js +1 -6
- package/dist/formations/prism/shader.js +3 -10
- package/dist/formations/prism/spectrum.d.ts +10 -0
- package/dist/formations/prism/spectrum.js +46 -0
- package/dist/formations/stack/art.d.ts +34 -0
- package/dist/formations/stack/art.js +171 -0
- package/dist/formations/stack/geometry.d.ts +10 -0
- package/dist/formations/stack/geometry.js +48 -0
- package/dist/formations/stack/index.d.ts +25 -0
- package/dist/formations/stack/index.js +76 -0
- package/dist/formations/stack/shader.js +193 -0
- package/dist/formations/threshold/geometry.js +98 -0
- package/dist/formations/threshold/index.d.ts +16 -0
- package/dist/formations/threshold/index.js +75 -0
- package/dist/formations/threshold/shader.js +186 -0
- package/dist/gl/glsl.d.ts +4 -0
- package/dist/gl/glsl.js +10 -2
- package/dist/gl/math.d.ts +1 -0
- package/dist/gl/shapes.d.ts +53 -0
- package/dist/gl/shapes.js +72 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +3 -2
- package/package.json +1 -4
package/README.md
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
The scroll-driven WebGL particle scene behind the uxfront.com family of homepages (UXFront, Open Components, Unframework, Styleframe, Inkline). One GPU particle system turns into a new **formation** for each section of the page as you scroll. The package has no framework dependency: `@uxfront/ui` wraps it in Vue components, and any other page can drive it directly.
|
|
4
4
|
|
|
5
5
|
- **A pipeline.** Morphs between formations under curl noise, an intro that rises from a floor line, a cursor lens, a click shockwave, a mirror floor, light trails, bloom and a filmic composite.
|
|
6
|
-
- **A catalog.**
|
|
7
|
-
- **A controller.** `createExperience` maps the page's sections to formations,
|
|
6
|
+
- **A catalog.** Eight formations: `monolith`, `plates`, `prism`, `tokens`, `ink`, `corridor`, `stack` and `threshold`.
|
|
7
|
+
- **A controller.** `createExperience` maps the page's sections to formations, reveals copy, steps through highlights and pins DOM labels to the formations.
|
|
8
8
|
|
|
9
9
|
Pages stay fast. The engine and each formation's GLSL are separate chunks, imported only once the page is idle. Shaders compile without blocking the main thread. Slow GPUs get fewer particles at a lower resolution, and without a capable GPU (no WebGL2, a software rasterizer, a lost context) the state switches to `"fallback"`, so the page can show a static image instead.
|
|
10
10
|
|
|
@@ -46,7 +46,7 @@ const experience = createExperience({
|
|
|
46
46
|
experience.subscribe(({ chapter, status, motion }) => {
|
|
47
47
|
// Update a HUD, a nav, the fallback…
|
|
48
48
|
});
|
|
49
|
-
experience.setMotion(false); // pause the clock
|
|
49
|
+
experience.setMotion(false); // pause the clock
|
|
50
50
|
experience.destroy();
|
|
51
51
|
```
|
|
52
52
|
|
|
@@ -60,7 +60,7 @@ experience.destroy();
|
|
|
60
60
|
| `data-steps="n"` on a section | While pinned, the section gets `data-step="0…n-1"` as it is read, to highlight `[data-step-item]`s. |
|
|
61
61
|
| `[data-reveal]` under `root` | Gets `.is-in` once scrolled into view. |
|
|
62
62
|
| `[data-anchor="key:id"]` under `anchorRoots` | Positioned (`transform`, `opacity`, `visibility`) over the formation's anchor while it shows. |
|
|
63
|
-
|
|
|
63
|
+
| `[data-progress]` under `root` | Gets `--ux-progress`: page scroll, 0 → 1. |
|
|
64
64
|
|
|
65
65
|
Portrait, squarish and small screens use each formation's `mobile` framing, which leaves the top of the screen to the formation. Lay the copy out with the same breakpoints, exported as `STACKED_QUERY`.
|
|
66
66
|
|
|
@@ -68,14 +68,16 @@ Portrait, squarish and small screens use each formation's `mobile` framing, whic
|
|
|
68
68
|
|
|
69
69
|
Every factory takes `{ label, key?, views?, look? }`. `label` is shown in the HUD. `views` overrides the framing, for example to put a formation on the other side of the copy: `tokens({ label, views: { desktop: { shift: [0.42, 0.02] } } })`. `key` is only needed to use the same formation twice.
|
|
70
70
|
|
|
71
|
-
| Formation
|
|
72
|
-
|
|
|
73
|
-
| `monolith`
|
|
74
|
-
| `plates`
|
|
75
|
-
| `prism`
|
|
76
|
-
| `tokens`
|
|
77
|
-
| `ink`
|
|
78
|
-
| `corridor`
|
|
71
|
+
| Formation | Shows | Anchors |
|
|
72
|
+
| ----------- | -------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- |
|
|
73
|
+
| `monolith` | A 1:4:9 slab of light over a mirror floor, the UXFront mark inlaid in it. | None |
|
|
74
|
+
| `plates` | Three glass plates with line art, drifting apart. `art` swaps the drawings. | `plates:0`–`plates:2`, at the plates' edges |
|
|
75
|
+
| `prism` | A beam split into seven rails that grow as the chapter is read. | `prism:0`–`prism:6`, at the rails' ends |
|
|
76
|
+
| `tokens` | A framed token matrix re-themed in waves. `next()` skips to the next theme. | `tokens:theme`, writes into `[data-theme-name]` |
|
|
77
|
+
| `ink` | Coloured inks poured into water. Scrolling speeds the pour up, or drives it without motion. | None |
|
|
78
|
+
| `corridor` | A corridor of streaking light with long trails. Suits a closing section. | None |
|
|
79
|
+
| `stack` | Seven glass cards dealt as the chapter is read, one per rail, each holding the same component. `art` swaps it. | `stack:0`–`stack:6`, in the cards' headers |
|
|
80
|
+
| `threshold` | The prism's seven beams cross a soap film of light and converge into one white stream. | `threshold:stream`, above the stream |
|
|
79
81
|
|
|
80
82
|
## Writing a formation
|
|
81
83
|
|
|
@@ -121,7 +123,9 @@ Particle $main(uint id, float sel, Frame f) {
|
|
|
121
123
|
- `$name` identifiers are private: the scene rewrites them to `key_name`, so formations never clash.
|
|
122
124
|
- `$main` returns the position, colour, size and `refl` (mirror reflectivity) of particle `id`. `sel` spreads evenly over [0, 1) across the particles, to split them between the parts of a formation.
|
|
123
125
|
- `Frame f` holds `local` (progress while pinned: 0 before, 1 after), `approach` (0 → 1 while the section scrolls in) and `time`.
|
|
124
|
-
- Shared helpers: `hashU`, `rnd`, `seedOf`, `gauss`, `noised`, `curl`, `bitangent`, `bezier3`, `rrectPoint`, `PI`, `TAU` and `FLOOR_Y`.
|
|
126
|
+
- Shared helpers: `hashU`, `rnd`, `seedOf`, `gauss`, `noised`, `curl`, `bitangent`, `bezier3`, `rrectPoint`, `shapePoint`, `PI`, `TAU` and `FLOOR_Y`.
|
|
127
|
+
- `glslFloat`, `glslVec` and `glslArray` write numbers into the GLSL as constants. `packShapes` packs line art (segments, rounded rectangles, circles, discs and fills) into rows for `shapePoint`, which places a particle on it. `stack` and `plates` draw their art this way.
|
|
128
|
+
- A formation that follows the prism can take its `RAILS` and `SPECTRUM` from `@uxfront/scene/formations`, so rail `i` keeps its colour.
|
|
125
129
|
- `setup` uploads uniforms once. `update(uniforms, frame)` runs every frame with the formation's `local`, `approach`, `presence`, `time`, `dt`, `motion` and `scrolled`.
|
|
126
130
|
- `anchors` pin DOM labels: `place(progress, out)` writes a world position and returns extra visibility, and `render(el, progress)` can update the label's content.
|
|
127
131
|
|
package/dist/experience.d.ts
CHANGED
|
@@ -14,8 +14,9 @@ export interface ExperienceState {
|
|
|
14
14
|
}
|
|
15
15
|
export interface ExperienceOptions {
|
|
16
16
|
/**
|
|
17
|
-
* Holds the `[data-stage]` sections, one per formation in DOM order,
|
|
18
|
-
* `[data-reveal]` blocks
|
|
17
|
+
* Holds the `[data-stage]` sections, one per formation in DOM order, the
|
|
18
|
+
* `[data-reveal]` blocks and the `[data-progress]` elements, which receive
|
|
19
|
+
* `--ux-progress` (page scroll, 0 → 1).
|
|
19
20
|
*/
|
|
20
21
|
root: HTMLElement;
|
|
21
22
|
canvas: HTMLCanvasElement;
|
|
@@ -27,14 +28,16 @@ export interface Experience {
|
|
|
27
28
|
readonly state: Readonly<ExperienceState>;
|
|
28
29
|
/** Called after every change of `state`. Returns an unsubscribe function. */
|
|
29
30
|
subscribe(listener: (state: Readonly<ExperienceState>) => void): () => void;
|
|
31
|
+
/** Runs or pauses the scene's clock. Scrolling stays native either way. */
|
|
30
32
|
setMotion(on: boolean): void;
|
|
31
33
|
destroy(): void;
|
|
32
34
|
}
|
|
33
35
|
export declare const initialExperienceState: () => ExperienceState;
|
|
34
36
|
/**
|
|
35
|
-
* Drives a page:
|
|
36
|
-
*
|
|
37
|
-
*
|
|
37
|
+
* Drives a page: the scroll → formation mapping, reveals and step
|
|
38
|
+
* highlights, pointer input, the GPU engine (booted once the page is idle)
|
|
39
|
+
* and the labels pinned to the formations. Client-only. Scrolling stays
|
|
40
|
+
* native, so the page scrolls smoothly even when the GPU drops frames.
|
|
38
41
|
*/
|
|
39
42
|
export declare function createExperience({ root, canvas, formations, anchorRoots }: ExperienceOptions): Experience;
|
|
40
43
|
//#endregion
|
package/dist/experience.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { clamp, damp, projectToScreen } from "./gl/math.js";
|
|
2
2
|
import { progressOf, stageAt } from "./gl/stage.js";
|
|
3
|
-
import Lenis from "lenis";
|
|
4
3
|
//#region src/experience.ts
|
|
5
4
|
const initialExperienceState = () => ({
|
|
6
5
|
chapter: 0,
|
|
@@ -34,9 +33,10 @@ function whenIdle(callback) {
|
|
|
34
33
|
else window.addEventListener("load", schedule, { once: true });
|
|
35
34
|
}
|
|
36
35
|
/**
|
|
37
|
-
* Drives a page:
|
|
38
|
-
*
|
|
39
|
-
*
|
|
36
|
+
* Drives a page: the scroll → formation mapping, reveals and step
|
|
37
|
+
* highlights, pointer input, the GPU engine (booted once the page is idle)
|
|
38
|
+
* and the labels pinned to the formations. Client-only. Scrolling stays
|
|
39
|
+
* native, so the page scrolls smoothly even when the GPU drops frames.
|
|
40
40
|
*/
|
|
41
41
|
function createExperience({ root, canvas, formations, anchorRoots = [] }) {
|
|
42
42
|
const reducedQuery = matchMedia("(prefers-reduced-motion: reduce)");
|
|
@@ -55,31 +55,21 @@ function createExperience({ root, canvas, formations, anchorRoots = [] }) {
|
|
|
55
55
|
listeners.forEach((listener) => listener(state));
|
|
56
56
|
};
|
|
57
57
|
let engine = null;
|
|
58
|
-
let lenis = null;
|
|
59
58
|
let disposed = false;
|
|
60
59
|
let sections = [];
|
|
61
60
|
let viewport = window.innerHeight;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
wheelMultiplier: .9
|
|
68
|
-
});
|
|
69
|
-
else if (!state.motion && lenis) {
|
|
70
|
-
lenis.destroy();
|
|
71
|
-
lenis = null;
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
syncLenis();
|
|
75
|
-
const setMotion = (on) => {
|
|
76
|
-
set({ motion: on });
|
|
77
|
-
syncLenis();
|
|
78
|
-
};
|
|
61
|
+
let maxScroll = 1;
|
|
62
|
+
let canvasWidth = 1;
|
|
63
|
+
let canvasHeight = 1;
|
|
64
|
+
const html = document.documentElement;
|
|
65
|
+
const setMotion = (on) => set({ motion: on });
|
|
79
66
|
const onReducedChange = () => setMotion(!reducedQuery.matches);
|
|
80
67
|
reducedQuery.addEventListener("change", onReducedChange);
|
|
81
68
|
const measure = () => {
|
|
82
69
|
viewport = window.innerHeight;
|
|
70
|
+
maxScroll = Math.max(1, html.scrollHeight - viewport);
|
|
71
|
+
canvasWidth = canvas.clientWidth;
|
|
72
|
+
canvasHeight = canvas.clientHeight;
|
|
83
73
|
const scrollY = window.scrollY;
|
|
84
74
|
sections = Array.from(root.querySelectorAll("[data-stage]")).map((el) => {
|
|
85
75
|
const rect = el.getBoundingClientRect();
|
|
@@ -147,15 +137,13 @@ function createExperience({ root, canvas, formations, anchorRoots = [] }) {
|
|
|
147
137
|
0
|
|
148
138
|
];
|
|
149
139
|
const updateAnchors = (stage, local) => {
|
|
150
|
-
const width = canvas.clientWidth;
|
|
151
|
-
const height = canvas.clientHeight;
|
|
152
140
|
const time = engine?.time ?? 0;
|
|
153
141
|
for (const { el, anchor, index } of pins) {
|
|
154
142
|
const progress = progressOf(index, stage, local, time);
|
|
155
143
|
let visible = engine ? progress.presence * progress.presence : 0;
|
|
156
144
|
if (visible > .001) {
|
|
157
145
|
visible *= anchor.place(progress, anchorPos);
|
|
158
|
-
if (!projectToScreen(screenPos, engine.viewProjection, anchorPos,
|
|
146
|
+
if (!projectToScreen(screenPos, engine.viewProjection, anchorPos, canvasWidth, canvasHeight)) visible = 0;
|
|
159
147
|
}
|
|
160
148
|
if (visible > .001) {
|
|
161
149
|
el.style.transform = `translate3d(${screenPos[0].toFixed(1)}px, ${screenPos[1].toFixed(1)}px, 0)`;
|
|
@@ -169,35 +157,38 @@ function createExperience({ root, canvas, formations, anchorRoots = [] }) {
|
|
|
169
157
|
let last = performance.now();
|
|
170
158
|
let stage = -1;
|
|
171
159
|
let local = 0;
|
|
160
|
+
/** The scroll position the scene follows, eased while Motion is on. */
|
|
161
|
+
let followY = 0;
|
|
172
162
|
let lastScrollY = window.scrollY;
|
|
173
163
|
let activeSection = null;
|
|
174
164
|
let statsClock = 0;
|
|
175
|
-
const
|
|
165
|
+
const progressEls = Array.from(root.querySelectorAll("[data-progress]"));
|
|
166
|
+
let progressText = "";
|
|
176
167
|
const tick = (now) => {
|
|
177
168
|
raf = requestAnimationFrame(tick);
|
|
178
169
|
const dt = Math.min(.1, Math.max(0, (now - last) / 1e3));
|
|
179
170
|
last = now;
|
|
180
|
-
lenis?.raf(now);
|
|
181
171
|
const scrollY = window.scrollY;
|
|
182
172
|
const scrolled = Math.abs(scrollY - lastScrollY) / viewport;
|
|
183
173
|
lastScrollY = scrollY;
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
} else {
|
|
189
|
-
stage = damp(stage, target.stage, 5, dt);
|
|
190
|
-
local = damp(local, target.local, 6, dt);
|
|
191
|
-
if (Math.abs(stage - target.stage) < 5e-4) stage = target.stage;
|
|
174
|
+
if (stage < 0 || !state.motion) followY = scrollY;
|
|
175
|
+
else {
|
|
176
|
+
followY = damp(followY, scrollY, 5, dt);
|
|
177
|
+
if (Math.abs(followY - scrollY) < .5) followY = scrollY;
|
|
192
178
|
}
|
|
179
|
+
({stage, local} = stageAt(sections, followY));
|
|
193
180
|
const held = Math.round(stage);
|
|
194
181
|
const section = sections[held]?.el ?? null;
|
|
195
|
-
|
|
182
|
+
const activeId = section?.id || null;
|
|
183
|
+
if (held !== state.chapter || activeId !== state.activeId) set({
|
|
196
184
|
chapter: held,
|
|
197
|
-
activeId
|
|
185
|
+
activeId
|
|
198
186
|
});
|
|
199
|
-
const
|
|
200
|
-
|
|
187
|
+
const nextProgress = clamp(scrollY / maxScroll, 0, 1).toFixed(4);
|
|
188
|
+
if (nextProgress !== progressText) {
|
|
189
|
+
progressText = nextProgress;
|
|
190
|
+
for (const el of progressEls) el.style.setProperty("--ux-progress", progressText);
|
|
191
|
+
}
|
|
201
192
|
if (section !== activeSection) {
|
|
202
193
|
activeSection?.removeAttribute("data-step");
|
|
203
194
|
activeSection = section;
|
|
@@ -295,8 +286,6 @@ function createExperience({ root, canvas, formations, anchorRoots = [] }) {
|
|
|
295
286
|
document.documentElement.removeEventListener("pointerleave", onPointerLeave);
|
|
296
287
|
window.removeEventListener("blur", onPointerLeave);
|
|
297
288
|
canvas.removeEventListener("webglcontextrestored", onContextRestored);
|
|
298
|
-
lenis?.destroy();
|
|
299
|
-
lenis = null;
|
|
300
289
|
engine?.destroy();
|
|
301
290
|
engine = null;
|
|
302
291
|
}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { corridor } from "./corridor/index.js";
|
|
2
2
|
import { ink } from "./ink/index.js";
|
|
3
3
|
import { monolith } from "./monolith/index.js";
|
|
4
|
-
import { OPEN_COMPONENTS_ART, PlateShape, circle, disc, plateBorder, rrect, seg } from "./plates/art.js";
|
|
4
|
+
import { OPEN_COMPONENTS_ART, PlateShape, circle, disc, fill, plateBorder, rrect, seg } from "./plates/art.js";
|
|
5
5
|
import { PlatesOptions, plates } from "./plates/index.js";
|
|
6
6
|
import { PLATE } from "./plates/geometry.js";
|
|
7
7
|
import { prism } from "./prism/index.js";
|
|
8
8
|
import { RAILS } from "./prism/geometry.js";
|
|
9
|
+
import { SPECTRUM } from "./prism/spectrum.js";
|
|
10
|
+
import { CARD_ROLE, CardRole, CardShape, KNOB_TRAVEL, SIGN_UP_FORM_ART } from "./stack/art.js";
|
|
11
|
+
import { StackOptions, stack } from "./stack/index.js";
|
|
12
|
+
import { CARD, CARD_NAME } from "./stack/geometry.js";
|
|
13
|
+
import { threshold } from "./threshold/index.js";
|
|
9
14
|
import { THEMES, Theme } from "./tokens/geometry.js";
|
|
10
15
|
import { TokensFormation, tokens } from "./tokens/index.js";
|
|
11
|
-
export { OPEN_COMPONENTS_ART, PLATE, type PlateShape, type PlatesOptions, RAILS, THEMES, type Theme, type TokensFormation, circle, corridor, disc, ink, monolith, plateBorder, plates, prism, rrect, seg, tokens };
|
|
16
|
+
export { CARD, CARD_NAME, CARD_ROLE, type CardRole, type CardShape, KNOB_TRAVEL, OPEN_COMPONENTS_ART, PLATE, type PlateShape, type PlatesOptions, RAILS, SIGN_UP_FORM_ART, SPECTRUM, type StackOptions, THEMES, type Theme, type TokensFormation, circle, corridor, disc, fill, ink, monolith, plateBorder, plates, prism, rrect, seg, stack, threshold, tokens };
|
package/dist/formations/index.js
CHANGED
|
@@ -3,9 +3,14 @@ import { ink } from "./ink/index.js";
|
|
|
3
3
|
import { monolith } from "./monolith/index.js";
|
|
4
4
|
import { PLATE } from "./plates/geometry.js";
|
|
5
5
|
import { plates } from "./plates/index.js";
|
|
6
|
-
import { OPEN_COMPONENTS_ART, circle, disc, plateBorder, rrect, seg } from "./plates/art.js";
|
|
6
|
+
import { OPEN_COMPONENTS_ART, circle, disc, fill, plateBorder, rrect, seg } from "./plates/art.js";
|
|
7
7
|
import { RAILS } from "./prism/geometry.js";
|
|
8
8
|
import { prism } from "./prism/index.js";
|
|
9
|
+
import { SPECTRUM } from "./prism/spectrum.js";
|
|
10
|
+
import { CARD, CARD_NAME } from "./stack/geometry.js";
|
|
11
|
+
import { stack } from "./stack/index.js";
|
|
12
|
+
import { CARD_ROLE, KNOB_TRAVEL, SIGN_UP_FORM_ART } from "./stack/art.js";
|
|
13
|
+
import { threshold } from "./threshold/index.js";
|
|
9
14
|
import { THEMES } from "./tokens/geometry.js";
|
|
10
15
|
import { tokens } from "./tokens/index.js";
|
|
11
|
-
export { OPEN_COMPONENTS_ART, PLATE, RAILS, THEMES, circle, corridor, disc, ink, monolith, plateBorder, plates, prism, rrect, seg, tokens };
|
|
16
|
+
export { CARD, CARD_NAME, CARD_ROLE, KNOB_TRAVEL, OPEN_COMPONENTS_ART, PLATE, RAILS, SIGN_UP_FORM_ART, SPECTRUM, THEMES, circle, corridor, disc, fill, ink, monolith, plateBorder, plates, prism, rrect, seg, stack, threshold, tokens };
|
|
@@ -1,35 +1,13 @@
|
|
|
1
1
|
import { Vec2 } from "../../gl/math.js";
|
|
2
|
+
import { Shape } from "../../gl/shapes.js";
|
|
2
3
|
//#region src/formations/plates/art.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* Plate artwork, drawn by the shader from a uniform table. Coordinates are
|
|
5
6
|
* plate-local (`PLATE` half extents): u to the right, v away from the viewer.
|
|
6
7
|
* `plate` is 0 (top), 1 or 2 (bottom).
|
|
7
8
|
*/
|
|
8
|
-
export type PlateShape = {
|
|
9
|
-
kind: "seg";
|
|
9
|
+
export type PlateShape = Shape & {
|
|
10
10
|
plate: number;
|
|
11
|
-
a: Vec2;
|
|
12
|
-
b: Vec2;
|
|
13
|
-
bright: number;
|
|
14
|
-
} | {
|
|
15
|
-
kind: "rrect";
|
|
16
|
-
plate: number;
|
|
17
|
-
c: Vec2;
|
|
18
|
-
h: Vec2;
|
|
19
|
-
r: number;
|
|
20
|
-
bright: number;
|
|
21
|
-
} | {
|
|
22
|
-
kind: "circle";
|
|
23
|
-
plate: number;
|
|
24
|
-
c: Vec2;
|
|
25
|
-
r: number;
|
|
26
|
-
bright: number;
|
|
27
|
-
} | {
|
|
28
|
-
kind: "disc";
|
|
29
|
-
plate: number;
|
|
30
|
-
c: Vec2;
|
|
31
|
-
r: number;
|
|
32
|
-
bright: number;
|
|
33
11
|
};
|
|
34
12
|
/** A line segment. */
|
|
35
13
|
export declare const seg: (plate: number, a: Vec2, b: Vec2, bright?: number) => PlateShape;
|
|
@@ -39,6 +17,8 @@ export declare const rrect: (plate: number, c: Vec2, h: Vec2, r: number, bright?
|
|
|
39
17
|
export declare const circle: (plate: number, c: Vec2, r: number, bright?: number) => PlateShape;
|
|
40
18
|
/** A filled disc. */
|
|
41
19
|
export declare const disc: (plate: number, c: Vec2, r: number, bright?: number) => PlateShape;
|
|
20
|
+
/** A filled rounded rectangle: centre, half size and corner radius. */
|
|
21
|
+
export declare const fill: (plate: number, c: Vec2, h: Vec2, r: number, bright?: number) => PlateShape;
|
|
42
22
|
/** The plate's own border. */
|
|
43
23
|
export declare const plateBorder: (plate: number, bright: number) => PlateShape;
|
|
44
24
|
/** Open Components: an interface (UX), its API (DX) and its semantic tree (AX). */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { packShapes } from "../../gl/shapes.js";
|
|
1
2
|
import { PLATE } from "./geometry.js";
|
|
2
3
|
//#region src/formations/plates/art.ts
|
|
3
4
|
/** A line segment. */
|
|
@@ -33,6 +34,15 @@ const disc = (plate, c, r, bright = 1) => ({
|
|
|
33
34
|
r,
|
|
34
35
|
bright
|
|
35
36
|
});
|
|
37
|
+
/** A filled rounded rectangle: centre, half size and corner radius. */
|
|
38
|
+
const fill = (plate, c, h, r, bright = .3) => ({
|
|
39
|
+
kind: "fill",
|
|
40
|
+
plate,
|
|
41
|
+
c,
|
|
42
|
+
h,
|
|
43
|
+
r,
|
|
44
|
+
bright
|
|
45
|
+
});
|
|
36
46
|
/** The plate's own border. */
|
|
37
47
|
const plateBorder = (plate, bright) => rrect(plate, [0, 0], PLATE, .14, bright);
|
|
38
48
|
const uxPlate = [
|
|
@@ -141,98 +151,24 @@ const OPEN_COMPONENTS_ART = [
|
|
|
141
151
|
...dxPlate,
|
|
142
152
|
...axPlate
|
|
143
153
|
];
|
|
144
|
-
|
|
145
|
-
if (shape.kind === "seg") return Math.hypot(shape.b[0] - shape.a[0], shape.b[1] - shape.a[1]);
|
|
146
|
-
if (shape.kind === "rrect") {
|
|
147
|
-
const r = Math.min(shape.r, shape.h[0], shape.h[1]);
|
|
148
|
-
return 4 * (shape.h[0] + shape.h[1]) - 8 * r + 2 * Math.PI * r;
|
|
149
|
-
}
|
|
150
|
-
if (shape.kind === "circle") return 2 * Math.PI * shape.r;
|
|
151
|
-
return Math.PI * shape.r * shape.r * 24;
|
|
152
|
-
};
|
|
153
|
-
/**
|
|
154
|
-
* Packs plate artwork into uniform arrays. Particles pick a shape by
|
|
155
|
-
* binary-searching the CDF, so every line gets the same particle density.
|
|
156
|
-
*/
|
|
154
|
+
/** Packs plate artwork into uniform arrays, the plate in each shape's tag. */
|
|
157
155
|
function buildShapeTable(shapes) {
|
|
158
156
|
if (shapes.length === 0) throw new Error("Plate artwork needs at least one shape");
|
|
159
157
|
if (shapes.length > 64) throw new Error(`Plate artwork is limited to 64 shapes`);
|
|
158
|
+
const packed = packShapes(shapes, (shape) => shape.plate);
|
|
160
159
|
const a = /* @__PURE__ */ new Float32Array(256);
|
|
161
160
|
const b = /* @__PURE__ */ new Float32Array(256);
|
|
162
161
|
const cdf = /* @__PURE__ */ new Float32Array(64);
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
shapes.forEach((shape, i) => {
|
|
167
|
-
running += weights[i];
|
|
168
|
-
cdf[i] = running / totalWeight;
|
|
169
|
-
const o = i * 4;
|
|
170
|
-
switch (shape.kind) {
|
|
171
|
-
case "seg":
|
|
172
|
-
a.set([
|
|
173
|
-
shape.a[0],
|
|
174
|
-
shape.a[1],
|
|
175
|
-
shape.b[0],
|
|
176
|
-
shape.b[1]
|
|
177
|
-
], o);
|
|
178
|
-
b.set([
|
|
179
|
-
0,
|
|
180
|
-
0,
|
|
181
|
-
shape.plate,
|
|
182
|
-
shape.bright
|
|
183
|
-
], o);
|
|
184
|
-
break;
|
|
185
|
-
case "rrect":
|
|
186
|
-
a.set([
|
|
187
|
-
shape.c[0],
|
|
188
|
-
shape.c[1],
|
|
189
|
-
shape.h[0],
|
|
190
|
-
shape.h[1]
|
|
191
|
-
], o);
|
|
192
|
-
b.set([
|
|
193
|
-
1,
|
|
194
|
-
shape.r,
|
|
195
|
-
shape.plate,
|
|
196
|
-
shape.bright
|
|
197
|
-
], o);
|
|
198
|
-
break;
|
|
199
|
-
case "circle":
|
|
200
|
-
a.set([
|
|
201
|
-
shape.c[0],
|
|
202
|
-
shape.c[1],
|
|
203
|
-
shape.r,
|
|
204
|
-
0
|
|
205
|
-
], o);
|
|
206
|
-
b.set([
|
|
207
|
-
2,
|
|
208
|
-
0,
|
|
209
|
-
shape.plate,
|
|
210
|
-
shape.bright
|
|
211
|
-
], o);
|
|
212
|
-
break;
|
|
213
|
-
case "disc":
|
|
214
|
-
a.set([
|
|
215
|
-
shape.c[0],
|
|
216
|
-
shape.c[1],
|
|
217
|
-
shape.r,
|
|
218
|
-
0
|
|
219
|
-
], o);
|
|
220
|
-
b.set([
|
|
221
|
-
3,
|
|
222
|
-
0,
|
|
223
|
-
shape.plate,
|
|
224
|
-
shape.bright
|
|
225
|
-
], o);
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
cdf[shapes.length - 1] = 1.0001;
|
|
162
|
+
a.set(packed.a.flat());
|
|
163
|
+
b.set(packed.b.flat());
|
|
164
|
+
cdf.set(packed.cdf);
|
|
229
165
|
return {
|
|
230
166
|
a,
|
|
231
167
|
b,
|
|
232
168
|
cdf,
|
|
233
169
|
count: shapes.length,
|
|
234
|
-
totalWeight
|
|
170
|
+
totalWeight: packed.totalWeight
|
|
235
171
|
};
|
|
236
172
|
}
|
|
237
173
|
//#endregion
|
|
238
|
-
export { OPEN_COMPONENTS_ART, buildShapeTable, circle, disc, plateBorder, rrect, seg };
|
|
174
|
+
export { OPEN_COMPONENTS_ART, buildShapeTable, circle, disc, fill, plateBorder, rrect, seg };
|
|
@@ -65,12 +65,7 @@ Particle $main(uint id, float sel, Frame f) {
|
|
|
65
65
|
int i = $findShape(a);
|
|
66
66
|
vec4 A = $shapeA[i];
|
|
67
67
|
vec4 B = $shapeB[i];
|
|
68
|
-
|
|
69
|
-
vec2 q;
|
|
70
|
-
if (type == 0) q = mix(A.xy, A.zw, b);
|
|
71
|
-
else if (type == 1) q = rrectPoint(A, B.y, b);
|
|
72
|
-
else if (type == 2) q = A.xy + A.z * vec2(cos(b * TAU), sin(b * TAU));
|
|
73
|
-
else q = A.xy + A.z * sqrt(c) * vec2(cos(b * TAU), sin(b * TAU));
|
|
68
|
+
vec2 q = shapePoint(A, B, b, c);
|
|
74
69
|
int k = int(B.z + 0.5);
|
|
75
70
|
float glint = exp(-pow((q.x - sweep) * 3.0, 2.0));
|
|
76
71
|
P.pos = vec3(q.x, sep * (1.0 - float(k)), -q.y);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { glslFloat } from "../../gl/glsl.js";
|
|
1
|
+
import { glslArray, glslFloat, glslVec } from "../../gl/glsl.js";
|
|
2
2
|
import { RAIL_APPROACH, RAIL_X0, RAIL_X1 } from "./geometry.js";
|
|
3
|
+
import { SPECTRUM } from "./spectrum.js";
|
|
3
4
|
//#region src/formations/prism/shader.ts
|
|
4
5
|
const shader = { glsl: `
|
|
5
6
|
const vec2 $PA = vec2(0.0, 1.097);
|
|
@@ -12,15 +13,7 @@ const float $RAIL_X1 = ${glslFloat(RAIL_X1)};
|
|
|
12
13
|
|
|
13
14
|
// Angular, Svelte, Astro, Vue, React, Solid, Qwik: the spectrum happens to
|
|
14
15
|
// land close to each framework's own colour.
|
|
15
|
-
const vec3 $SPECTRUM[7] = vec3
|
|
16
|
-
vec3(1.0, 0.13, 0.16),
|
|
17
|
-
vec3(1.0, 0.4, 0.06),
|
|
18
|
-
vec3(1.0, 0.8, 0.14),
|
|
19
|
-
vec3(0.2, 1.0, 0.45),
|
|
20
|
-
vec3(0.16, 0.75, 1.0),
|
|
21
|
-
vec3(0.25, 0.36, 1.0),
|
|
22
|
-
vec3(0.64, 0.26, 1.0)
|
|
23
|
-
);
|
|
16
|
+
const vec3 $SPECTRUM[7] = ${glslArray("vec3", SPECTRUM.map(glslVec))};
|
|
24
17
|
|
|
25
18
|
// Rails start growing as the chapter scrolls in (see railProgress).
|
|
26
19
|
float $progress(Frame f) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Vec3 } from "../../gl/math.js";
|
|
2
|
+
//#region src/formations/prism/spectrum.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The prism's spectrum, one colour per rail, top to bottom (see `RAILS`). In
|
|
5
|
+
* that order it lands close to the colours of Angular, Svelte, Astro, Vue,
|
|
6
|
+
* React, Solid and Qwik. Formations that follow the prism keep each rail's
|
|
7
|
+
* colour.
|
|
8
|
+
*/
|
|
9
|
+
export declare const SPECTRUM: readonly Vec3[];
|
|
10
|
+
//#endregion
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//#region src/formations/prism/spectrum.ts
|
|
2
|
+
/**
|
|
3
|
+
* The prism's spectrum, one colour per rail, top to bottom (see `RAILS`). In
|
|
4
|
+
* that order it lands close to the colours of Angular, Svelte, Astro, Vue,
|
|
5
|
+
* React, Solid and Qwik. Formations that follow the prism keep each rail's
|
|
6
|
+
* colour.
|
|
7
|
+
*/
|
|
8
|
+
const SPECTRUM = [
|
|
9
|
+
[
|
|
10
|
+
1,
|
|
11
|
+
.13,
|
|
12
|
+
.16
|
|
13
|
+
],
|
|
14
|
+
[
|
|
15
|
+
1,
|
|
16
|
+
.4,
|
|
17
|
+
.06
|
|
18
|
+
],
|
|
19
|
+
[
|
|
20
|
+
1,
|
|
21
|
+
.8,
|
|
22
|
+
.14
|
|
23
|
+
],
|
|
24
|
+
[
|
|
25
|
+
.2,
|
|
26
|
+
1,
|
|
27
|
+
.45
|
|
28
|
+
],
|
|
29
|
+
[
|
|
30
|
+
.16,
|
|
31
|
+
.75,
|
|
32
|
+
1
|
|
33
|
+
],
|
|
34
|
+
[
|
|
35
|
+
.25,
|
|
36
|
+
.36,
|
|
37
|
+
1
|
|
38
|
+
],
|
|
39
|
+
[
|
|
40
|
+
.64,
|
|
41
|
+
.26,
|
|
42
|
+
1
|
|
43
|
+
]
|
|
44
|
+
];
|
|
45
|
+
//#endregion
|
|
46
|
+
export { SPECTRUM };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Shape } from "../../gl/shapes.js";
|
|
2
|
+
//#region src/formations/stack/art.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* What a shape does while the formation plays. Every card fills its form in on
|
|
5
|
+
* the same beat, because every card holds the same component: the `typing`
|
|
6
|
+
* line grows as the email is typed, with its `caret`, the toggle switches on
|
|
7
|
+
* (its `track` lights up and its `knob` slides `KNOB_TRAVEL` to the right) and
|
|
8
|
+
* the `button` is pressed.
|
|
9
|
+
*/
|
|
10
|
+
export declare const CARD_ROLE: {
|
|
11
|
+
readonly still: 0;
|
|
12
|
+
readonly knob: 1;
|
|
13
|
+
readonly track: 2;
|
|
14
|
+
readonly button: 3;
|
|
15
|
+
readonly typing: 4;
|
|
16
|
+
readonly caret: 5;
|
|
17
|
+
};
|
|
18
|
+
export type CardRole = (typeof CARD_ROLE)[keyof typeof CARD_ROLE];
|
|
19
|
+
/**
|
|
20
|
+
* Card artwork, in card-local art units (`CARD` half extents): x to the
|
|
21
|
+
* right, y up. The formation draws the card's border itself.
|
|
22
|
+
*/
|
|
23
|
+
export type CardShape = Shape & {
|
|
24
|
+
role?: CardRole;
|
|
25
|
+
};
|
|
26
|
+
/** How far a toggle's knob slides when it switches on. */
|
|
27
|
+
export declare const KNOB_TRAVEL = .08;
|
|
28
|
+
/**
|
|
29
|
+
* Unframework: one component, the same on every card. A sign-up form, with a
|
|
30
|
+
* header (the part that shows above the card in front), first and last name,
|
|
31
|
+
* an email, a "remember me" toggle, and cancel and submit buttons.
|
|
32
|
+
*/
|
|
33
|
+
export declare const SIGN_UP_FORM_ART: CardShape[];
|
|
34
|
+
//#endregion
|