@unoverse-platform/studio 0.1.25 → 0.1.27
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/package.json +1 -1
- package/screens/AtomsView.tsx +40 -2
- package/screens/ComponentsView.tsx +112 -21
- package/screens/NativeAppHost.tsx +8 -4
- package/screens/SourceView.tsx +1 -1
- package/screens/TemplatesView.tsx +52 -22
- package/screens/states.ts +27 -4
- package/src/PublishDialog.tsx +1 -1
- package/vendor/sdk/appEngine.tsx +44 -3
- package/vendor/sdk/lib/UnoverseComponent.tsx +1 -1
- package/vendor/sdk/lib/core/actions.ts +20 -6
- package/vendor/sdk/lib/core/analytics.ts +89 -0
- package/vendor/sdk/lib/core/client.ts +1 -1
- package/vendor/sdk/lib/core/index.ts +30 -0
- package/vendor/sdk/lib/core/store.ts +65 -38
- package/vendor/sdk/lib/core/templates.ts +252 -0
- package/vendor/sdk/lib/core/types.ts +40 -7
- package/vendor/sdk/lib/index.ts +9 -0
- package/vendor/sdk/lib/orb/ThinkingOrb.tsx +127 -0
- package/vendor/sdk/lib/orb/engine/braid.ts +50 -0
- package/vendor/sdk/lib/orb/engine/core.ts +157 -0
- package/vendor/sdk/lib/orb/engine/lattice.ts +205 -0
- package/vendor/sdk/lib/orb/engine/morph.ts +138 -0
- package/vendor/sdk/lib/orb/engine/orbits.ts +80 -0
- package/vendor/sdk/lib/orb/engine/profiles.ts +162 -0
- package/vendor/sdk/lib/orb/engine/registry.ts +24 -0
- package/vendor/sdk/lib/orb/engine/ribbon.ts +93 -0
- package/vendor/sdk/lib/orb/engine/types.ts +14 -0
- package/vendor/sdk/lib/orb/engine/web.ts +98 -0
- package/vendor/sdk/lib/orb/index.ts +20 -0
- package/vendor/sdk/lib/orb/presets.ts +104 -0
- package/vendor/sdk/lib/orb/theme.ts +83 -0
- package/vendor/sdk/lib/orb/types.ts +73 -0
- package/vendor/sdk/lib/primitives.tsx +114 -5
- package/vendor/sdk/lib/render.tsx +25 -5
- package/vendor/sdk/lib/style.ts +6 -2
- package/vendor/sdk/lib/template.tsx +77 -218
- package/vendor/sdk/main.tsx +7 -0
- package/vendor/skills/unoverse-create/SKILL.md +18 -18
- package/vendor/skills/unoverse-create/references/agent-skill.md +12 -12
- package/vendor/skills/unoverse-create/references/block.md +5 -5
- package/vendor/skills/unoverse-create/references/component.md +150 -75
- package/vendor/skills/unoverse-create/references/node.md +1 -1
- package/vendor/skills/unoverse-create/references/template.md +142 -82
- package/vendor/skills/unoverse-create/references/workflow.md +15 -15
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// Shared primitives for the dotted 3D thought-orbs. Ported from inkform
|
|
2
|
+
// (PlotterLab's HalftoneSphere lineage): honestly 3D — rotated,
|
|
3
|
+
// depth-shaded, z-sorted. Depth is carried by dot size and ink weight
|
|
4
|
+
// alone. Plain 2D canvas fills only: no ctx.filter, no SVG filters, so
|
|
5
|
+
// every mode renders identically in Chrome, Safari and Firefox.
|
|
6
|
+
|
|
7
|
+
export interface Dot {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
z: number;
|
|
11
|
+
r: number;
|
|
12
|
+
/** Ink value: 0 = darkest ink on paper. Mirrored on dark themes. */
|
|
13
|
+
white: number;
|
|
14
|
+
a?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** A stroked edge between two projected points (the `connecting` web). */
|
|
18
|
+
export interface Line {
|
|
19
|
+
x1: number;
|
|
20
|
+
y1: number;
|
|
21
|
+
x2: number;
|
|
22
|
+
y2: number;
|
|
23
|
+
/** Ink value, same convention as `Dot.white`. */
|
|
24
|
+
white: number;
|
|
25
|
+
a?: number;
|
|
26
|
+
w: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type Projector = (x: number, y: number, z: number) => [number, number, number];
|
|
30
|
+
|
|
31
|
+
export function lerp(a: number, b: number, f: number): number {
|
|
32
|
+
return a + (b - a) * f;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function frac(x: number): number {
|
|
36
|
+
return x - Math.floor(x);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Value noise on a 2D lattice — smooth, deterministic, cheap. */
|
|
40
|
+
export function vnoise(x: number, y: number): number {
|
|
41
|
+
const xi = Math.floor(x);
|
|
42
|
+
const yi = Math.floor(y);
|
|
43
|
+
let fx = x - xi;
|
|
44
|
+
let fy = y - yi;
|
|
45
|
+
fx = fx * fx * (3 - 2 * fx);
|
|
46
|
+
fy = fy * fy * (3 - 2 * fy);
|
|
47
|
+
const a = hashD(xi, yi);
|
|
48
|
+
const b = hashD(xi + 1, yi);
|
|
49
|
+
const c = hashD(xi, yi + 1);
|
|
50
|
+
const d = hashD(xi + 1, yi + 1);
|
|
51
|
+
return a + (b - a) * fx + (c - a) * fy + (a - b - c + d) * fx * fy;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Deterministic hash in [0, 1). */
|
|
55
|
+
export function hashD(a: number, b: number): number {
|
|
56
|
+
const h = Math.sin(a * 12.9898 + b * 78.233) * 43758.5453;
|
|
57
|
+
return h - Math.floor(h);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Stable directions on a unit sphere (Fibonacci lattice). */
|
|
61
|
+
export function fibDir(i: number, n: number): [number, number, number] {
|
|
62
|
+
const golden = Math.PI * (3 - Math.sqrt(5));
|
|
63
|
+
const y = 1 - (2 * (i + 0.5)) / n;
|
|
64
|
+
const rad = Math.sqrt(1 - y * y);
|
|
65
|
+
const a = i * golden;
|
|
66
|
+
return [rad * Math.cos(a), y, rad * Math.sin(a)];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Shortest signed angular distance, wrapped to (-π, π]. */
|
|
70
|
+
export function angleDelta(a: number, b: number): number {
|
|
71
|
+
return Math.atan2(Math.sin(a - b), Math.cos(a - b));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Shared spin + tilt + orthographic projection. */
|
|
75
|
+
export function makeProj(yaw: number, tilt: number, cx: number, cy: number, scale: number): Projector {
|
|
76
|
+
const st = Math.sin(tilt);
|
|
77
|
+
const ct = Math.cos(tilt);
|
|
78
|
+
const sy = Math.sin(yaw);
|
|
79
|
+
const cyw = Math.cos(yaw);
|
|
80
|
+
return (x, y, z) => {
|
|
81
|
+
const x1 = x * cyw + z * sy;
|
|
82
|
+
const z1 = -x * sy + z * cyw;
|
|
83
|
+
const y1 = y * ct - z1 * st;
|
|
84
|
+
const z2 = y * st + z1 * ct;
|
|
85
|
+
return [cx + x1 * scale, cy - y1 * scale, z2];
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* LOCAL EXTENSION (Unoverse): an optional brand INK the painters tint toward.
|
|
91
|
+
* The upstream engine paints matte grayscale only; the design system's LAW 1
|
|
92
|
+
* says every colour is a served token, so the host resolves its `color` token
|
|
93
|
+
* and hands the rgb here before each frame. null = the upstream neutral ink.
|
|
94
|
+
* A module-level current-ink is safe because frames draw synchronously.
|
|
95
|
+
*/
|
|
96
|
+
let INK: [number, number, number] | null = null;
|
|
97
|
+
export function setInk(rgb: [number, number, number] | null): void {
|
|
98
|
+
INK = rgb;
|
|
99
|
+
}
|
|
100
|
+
/** Depth-shaded channel: neutral grayscale, or the ink mixed toward the substrate. */
|
|
101
|
+
function shade(w: number, dark: boolean): [number, number, number] {
|
|
102
|
+
if (!INK) {
|
|
103
|
+
const g = Math.round((dark ? 1 - w : w) * 255);
|
|
104
|
+
return [g, g, g];
|
|
105
|
+
}
|
|
106
|
+
// Light substrate: near dots (w→0) are pure ink, far dots fade to paper.
|
|
107
|
+
// Dark substrate: the ink is pre-lightened so it pops, far dots fade to black.
|
|
108
|
+
const [r, g, b] = INK;
|
|
109
|
+
const mixTo = dark ? 0 : 255;
|
|
110
|
+
const base: [number, number, number] = dark
|
|
111
|
+
? [r + (255 - r) * 0.35, g + (255 - g) * 0.35, b + (255 - b) * 0.35]
|
|
112
|
+
: [r, g, b];
|
|
113
|
+
return [0, 1, 2].map((i) => Math.round(base[i] + (mixTo - base[i]) * w)) as [number, number, number];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Painter: z-sort far→near, matte depth-shaded dots. On dark substrates the
|
|
118
|
+
* ink value is mirrored (1 - white) so near dots read bright — the same
|
|
119
|
+
* depth language on an inverted substrate.
|
|
120
|
+
*/
|
|
121
|
+
export function paint(ctx: CanvasRenderingContext2D, dots: Dot[], dark: boolean, rMin = 0.3): void {
|
|
122
|
+
dots.sort((a, b) => a.z - b.z);
|
|
123
|
+
for (const d of dots) {
|
|
124
|
+
const alpha = d.a ?? 1;
|
|
125
|
+
if (alpha < 0.02) continue;
|
|
126
|
+
const w = Math.min(1, Math.max(0, d.white));
|
|
127
|
+
const [r, g, b] = shade(w, dark);
|
|
128
|
+
ctx.fillStyle = `rgba(${r},${g},${b},${alpha})`;
|
|
129
|
+
ctx.beginPath();
|
|
130
|
+
ctx.arc(d.x, d.y, Math.max(rMin, d.r), 0, Math.PI * 2);
|
|
131
|
+
ctx.fill();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Stroke pass for edge-based modes. Runs before `paint` so nodes sit on top. */
|
|
136
|
+
export function paintLines(ctx: CanvasRenderingContext2D, lines: Line[], dark: boolean): void {
|
|
137
|
+
for (const l of lines) {
|
|
138
|
+
const alpha = l.a ?? 1;
|
|
139
|
+
if (alpha < 0.02) continue;
|
|
140
|
+
const w = Math.min(1, Math.max(0, l.white));
|
|
141
|
+
const [r, g, b] = shade(w, dark);
|
|
142
|
+
ctx.strokeStyle = `rgba(${r},${g},${b},${alpha})`;
|
|
143
|
+
ctx.lineWidth = l.w;
|
|
144
|
+
ctx.beginPath();
|
|
145
|
+
ctx.moveTo(l.x1, l.y1);
|
|
146
|
+
ctx.lineTo(l.x2, l.y2);
|
|
147
|
+
ctx.stroke();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Dot radii were tuned for a 300pt frame; sub-linear scaling keeps small
|
|
153
|
+
* spinners legible. Lower pow = radii shrink less with size.
|
|
154
|
+
*/
|
|
155
|
+
export function radiusScale(size: number, pow: number): number {
|
|
156
|
+
return (size / 300) ** pow;
|
|
157
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// The sphere-lattice modes: globe (searching), rubik (solving) and
|
|
2
|
+
// wave (listening). All draw a lat/long dot field with mode-specific
|
|
3
|
+
// motion, then hand off to the shared z-sorted painter.
|
|
4
|
+
|
|
5
|
+
import type { Dot, ModeDraw } from './types';
|
|
6
|
+
import { angleDelta, hashD, makeProj, paint, radiusScale } from './core';
|
|
7
|
+
|
|
8
|
+
// --- the shared solver heartbeat (rubik) ------------------------------
|
|
9
|
+
// Rapid eased moves scramble, then replay in reverse (palindrome) so
|
|
10
|
+
// everything clicks back to solved, rests, repeats.
|
|
11
|
+
|
|
12
|
+
interface Move {
|
|
13
|
+
axis: 0 | 1 | 2;
|
|
14
|
+
lo: number;
|
|
15
|
+
hi: number;
|
|
16
|
+
ang: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function solveCycle(time: number, count: number, slotDur: number, rest: number) {
|
|
20
|
+
const cyc = 2 * count * slotDur + rest;
|
|
21
|
+
const tc = time % cyc;
|
|
22
|
+
const amount = new Array<number>(count).fill(0);
|
|
23
|
+
let active = -1;
|
|
24
|
+
if (tc < 2 * count * slotDur) {
|
|
25
|
+
const slot = Math.floor(tc / slotDur);
|
|
26
|
+
const p = (tc - slot * slotDur) / slotDur;
|
|
27
|
+
const cl = Math.min(1, p / 0.7);
|
|
28
|
+
const ep = 1 - (1 - cl) ** 3; // machine ease-out
|
|
29
|
+
if (slot < count) {
|
|
30
|
+
for (let i = 0; i < slot; i++) amount[i] = 1;
|
|
31
|
+
amount[slot] = ep;
|
|
32
|
+
active = slot;
|
|
33
|
+
} else {
|
|
34
|
+
const u = 2 * count - 1 - slot;
|
|
35
|
+
for (let i = 0; i < u; i++) amount[i] = 1;
|
|
36
|
+
amount[u] = 1 - ep;
|
|
37
|
+
active = u;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return { amount, active };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function applyMoves(
|
|
44
|
+
pt3: [number, number, number],
|
|
45
|
+
moves: Move[],
|
|
46
|
+
sc: { amount: number[]; active: number }
|
|
47
|
+
): [number, number, number, boolean] {
|
|
48
|
+
let [x, y, z] = pt3;
|
|
49
|
+
let inActive = false;
|
|
50
|
+
for (let i = 0; i < moves.length; i++) {
|
|
51
|
+
if (sc.amount[i] <= 0) continue;
|
|
52
|
+
const mv = moves[i];
|
|
53
|
+
const coord = mv.axis === 0 ? x : mv.axis === 1 ? y : z;
|
|
54
|
+
if (coord < mv.lo || coord >= mv.hi) continue;
|
|
55
|
+
if (i === sc.active) inActive = true;
|
|
56
|
+
const a = mv.ang * sc.amount[i];
|
|
57
|
+
const ca = Math.cos(a);
|
|
58
|
+
const sa = Math.sin(a);
|
|
59
|
+
if (mv.axis === 0) {
|
|
60
|
+
const y2 = y * ca - z * sa;
|
|
61
|
+
z = y * sa + z * ca;
|
|
62
|
+
y = y2;
|
|
63
|
+
} else if (mv.axis === 1) {
|
|
64
|
+
const x2 = x * ca + z * sa;
|
|
65
|
+
z = -x * sa + z * ca;
|
|
66
|
+
x = x2;
|
|
67
|
+
} else {
|
|
68
|
+
const x2 = x * ca - y * sa;
|
|
69
|
+
y = x * sa + y * ca;
|
|
70
|
+
x = x2;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return [x, y, z, inActive];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function makeMoves(count: number): Move[] {
|
|
77
|
+
const moves: Move[] = [];
|
|
78
|
+
for (let i = 0; i < count; i++) {
|
|
79
|
+
const axis = Math.min(2, Math.floor(hashD(i, 2.3) * 3)) as 0 | 1 | 2;
|
|
80
|
+
const lo = -1.0 + 0.5 * Math.min(3, Math.floor(hashD(i, 5.9) * 4));
|
|
81
|
+
const dir = hashD(i, 7.7) < 0.5 ? 1 : -1;
|
|
82
|
+
moves.push({ axis, lo, hi: lo + 0.5, ang: (dir * Math.PI) / 2 });
|
|
83
|
+
}
|
|
84
|
+
return moves;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// --- Globe: lat/long field, a scan meridian sweeps — searching --------
|
|
88
|
+
|
|
89
|
+
export const drawGlobe: ModeDraw = (ctx, size, t, dark, o) => {
|
|
90
|
+
const spin = 0.5;
|
|
91
|
+
const cx = size / 2;
|
|
92
|
+
const cy = size / 2;
|
|
93
|
+
const radius = (size / 2) * 0.82;
|
|
94
|
+
const tilt = 0.4 + 0.06 * Math.sin(t * 0.35);
|
|
95
|
+
const pt = makeProj(t * spin, tilt, cx, cy, radius);
|
|
96
|
+
// scan sweeps relative to the spin; scanMul scales that relative rate
|
|
97
|
+
const scan = t * (spin + (1.7 - spin) * (o.scanMul ?? 1));
|
|
98
|
+
const rs = radiusScale(size, o.rsPow ?? 0.6);
|
|
99
|
+
const dimBase = o.dimBase ?? 1;
|
|
100
|
+
|
|
101
|
+
const dots: Dot[] = [];
|
|
102
|
+
const latRings = o.latRings ?? 17;
|
|
103
|
+
const lonDensity = o.lonDensity ?? 44;
|
|
104
|
+
for (let li = 0; li <= latRings; li++) {
|
|
105
|
+
const lat = -Math.PI / 2 + (li / latRings) * Math.PI;
|
|
106
|
+
const cosLat = Math.cos(lat);
|
|
107
|
+
const sinLat = Math.sin(lat);
|
|
108
|
+
const lonCount = Math.max(1, Math.round(Math.abs(cosLat) * lonDensity));
|
|
109
|
+
for (let lj = 0; lj < lonCount; lj++) {
|
|
110
|
+
const lon = (lj / lonCount) * 2 * Math.PI;
|
|
111
|
+
const [px, py, z] = pt(cosLat * Math.cos(lon), sinLat, cosLat * Math.sin(lon));
|
|
112
|
+
const depth = (z + 1) / 2;
|
|
113
|
+
// the scan: a moving meridian read as a size ripple, not a shine
|
|
114
|
+
const d = angleDelta(lon + t * spin, scan);
|
|
115
|
+
const boost = Math.exp(-(d * d) / 0.18) * Math.max(0, z);
|
|
116
|
+
dots.push({
|
|
117
|
+
x: px,
|
|
118
|
+
y: py,
|
|
119
|
+
z,
|
|
120
|
+
r: ((o.rBase ?? 0.6) + (o.rDepth ?? 1.7) * depth + (o.rBoost ?? 1) * boost) * rs,
|
|
121
|
+
white: (o.inkFar ?? 0.62) - (o.inkSpan ?? 0.54) * depth,
|
|
122
|
+
// dimBase < 1 fades un-scanned dots so the meridian reads clearly
|
|
123
|
+
a: dimBase + (1 - dimBase) * Math.min(1, boost)
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
paint(ctx, dots, dark, o.rMin);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// --- Rubik: bands twist in quarter turns, scramble → solve — solving --
|
|
131
|
+
|
|
132
|
+
export const drawRubik: ModeDraw = (ctx, size, t, dark, o) => {
|
|
133
|
+
const cx = size / 2;
|
|
134
|
+
const cy = size / 2;
|
|
135
|
+
const R = (size / 2) * 0.82;
|
|
136
|
+
const pt = makeProj(t * 0.55, 0.35 + 0.1 * Math.sin(t * 0.9), cx, cy, R);
|
|
137
|
+
const rs = radiusScale(size, o.rsPow ?? 0.6);
|
|
138
|
+
const moveCount = o.moveCount ?? 14;
|
|
139
|
+
const moves = makeMoves(moveCount);
|
|
140
|
+
const sc = solveCycle(t, moveCount, 0.42, 1.2);
|
|
141
|
+
|
|
142
|
+
const dots: Dot[] = [];
|
|
143
|
+
const latRings = o.latRings ?? 15;
|
|
144
|
+
const lonDensity = o.lonDensity ?? 40;
|
|
145
|
+
for (let li = 0; li <= latRings; li++) {
|
|
146
|
+
const lat = -Math.PI / 2 + (li / latRings) * Math.PI;
|
|
147
|
+
const cosLat = Math.cos(lat);
|
|
148
|
+
const sinLat = Math.sin(lat);
|
|
149
|
+
const lonCount = Math.max(1, Math.round(Math.abs(cosLat) * lonDensity));
|
|
150
|
+
for (let lj = 0; lj < lonCount; lj++) {
|
|
151
|
+
const lon = (lj / lonCount) * 2 * Math.PI;
|
|
152
|
+
const [x, y, z, inActive] = applyMoves([cosLat * Math.cos(lon), sinLat, cosLat * Math.sin(lon)], moves, sc);
|
|
153
|
+
const [px, py, zr] = pt(x, y, z);
|
|
154
|
+
const depth = (zr + 1) / 2;
|
|
155
|
+
// the band being turned inks a touch darker — the "hand"
|
|
156
|
+
dots.push({
|
|
157
|
+
x: px,
|
|
158
|
+
y: py,
|
|
159
|
+
z: zr,
|
|
160
|
+
r: ((o.rBase ?? 0.6) + (o.rDepth ?? 1.7) * depth + (inActive ? (o.rActive ?? 0.3) : 0)) * rs,
|
|
161
|
+
white: (o.inkFar ?? 0.62) - (o.inkSpan ?? 0.54) * depth - (inActive ? 0.14 : 0)
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
paint(ctx, dots, dark, o.rMin);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// --- Wave: a waveform rolls through the rings — listening -------------
|
|
169
|
+
|
|
170
|
+
export const drawWave: ModeDraw = (ctx, size, t, dark, o) => {
|
|
171
|
+
const cx = size / 2;
|
|
172
|
+
const cy = size / 2;
|
|
173
|
+
// 0.76 base × 1.15 — the undulation pulls the sphere inward, so wave read
|
|
174
|
+
// ~15% smaller than the other lattice modes; scaled up to match them
|
|
175
|
+
const R = (size / 2) * 0.874;
|
|
176
|
+
const pt = makeProj(t * 0.18, 0.38, cx, cy, 1);
|
|
177
|
+
const rs = radiusScale(size, o.rsPow ?? 0.6);
|
|
178
|
+
|
|
179
|
+
const dots: Dot[] = [];
|
|
180
|
+
const rings = o.rings ?? 15;
|
|
181
|
+
const lonDensity = o.lonDensity ?? 40;
|
|
182
|
+
for (let ri = 0; ri <= rings; ri++) {
|
|
183
|
+
const lat = -Math.PI / 2 + (ri / rings) * Math.PI;
|
|
184
|
+
const cosLat = Math.cos(lat);
|
|
185
|
+
const sinLat = Math.sin(lat);
|
|
186
|
+
// two waves, different tempi — organic, never quite repeating
|
|
187
|
+
const w = 0.62 * Math.sin(t * 2.1 - ri * 0.52) + 0.38 * Math.sin(t * 1.27 + ri * 0.83);
|
|
188
|
+
const rr = R * (0.88 + 0.105 * w);
|
|
189
|
+
const lonCount = Math.max(1, Math.round(Math.abs(cosLat) * lonDensity));
|
|
190
|
+
for (let lj = 0; lj < lonCount; lj++) {
|
|
191
|
+
const lon = (lj / lonCount) * 2 * Math.PI;
|
|
192
|
+
const [px, py, z] = pt(cosLat * Math.cos(lon) * rr, sinLat * rr, cosLat * Math.sin(lon) * rr);
|
|
193
|
+
const depth = (z / R + 1) / 2;
|
|
194
|
+
const crest = Math.max(0, w);
|
|
195
|
+
dots.push({
|
|
196
|
+
x: px,
|
|
197
|
+
y: py,
|
|
198
|
+
z,
|
|
199
|
+
r: ((o.rBase ?? 0.6) + (o.rDepth ?? 1.7) * depth) * (1 + 0.4 * crest) * rs,
|
|
200
|
+
white: 0.66 - 0.56 * depth - 0.1 * crest
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
paint(ctx, dots, dark, o.rMin);
|
|
205
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// Morph: a dotted outline cycling circle → triangle → square → circle —
|
|
2
|
+
// the "shaping" state. Each shape is a continuous closed path
|
|
3
|
+
// parameterised by arc length (top-centre start, clockwise). Every
|
|
4
|
+
// frame the engine blends the two neighbouring paths, then lays the
|
|
5
|
+
// dots EVENLY along the blended outline — spacing stays uniform at
|
|
6
|
+
// every instant of the morph, holds and transitions alike. Plain
|
|
7
|
+
// circle fills only: no canvas/SVG filters, fully cross-browser.
|
|
8
|
+
|
|
9
|
+
import type { Dot, ModeDraw } from './types';
|
|
10
|
+
import { paint } from './core';
|
|
11
|
+
|
|
12
|
+
type Path = (f: number) => [number, number];
|
|
13
|
+
|
|
14
|
+
function smoothE(x: number): number {
|
|
15
|
+
return x * x * (3 - 2 * x);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function polyPath(verts: ReadonlyArray<readonly [number, number]>): Path {
|
|
19
|
+
const V = verts.length;
|
|
20
|
+
const L: number[] = [];
|
|
21
|
+
let total = 0;
|
|
22
|
+
for (let i = 0; i < V; i++) {
|
|
23
|
+
const a = verts[i];
|
|
24
|
+
const b = verts[(i + 1) % V];
|
|
25
|
+
const l = Math.hypot(b[0] - a[0], b[1] - a[1]);
|
|
26
|
+
L.push(l);
|
|
27
|
+
total += l;
|
|
28
|
+
}
|
|
29
|
+
return (f) => {
|
|
30
|
+
let target = f * total;
|
|
31
|
+
let i = 0;
|
|
32
|
+
while (target > L[i] && i < V - 1) {
|
|
33
|
+
target -= L[i];
|
|
34
|
+
i++;
|
|
35
|
+
}
|
|
36
|
+
const a = verts[i];
|
|
37
|
+
const b = verts[(i + 1) % V];
|
|
38
|
+
const ff = L[i] ? Math.min(1, target / L[i]) : 0;
|
|
39
|
+
return [a[0] + (b[0] - a[0]) * ff, a[1] + (b[1] - a[1]) * ff];
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const CIRCLE: Path = (f) => {
|
|
44
|
+
const a = -Math.PI / 2 + f * 2 * Math.PI;
|
|
45
|
+
return [Math.cos(a) * 0.24, Math.sin(a) * 0.24];
|
|
46
|
+
};
|
|
47
|
+
const TRIANGLE = polyPath([
|
|
48
|
+
[0.0, -0.26],
|
|
49
|
+
[0.24, 0.16],
|
|
50
|
+
[-0.24, 0.16]
|
|
51
|
+
]);
|
|
52
|
+
// 5-vertex walk so the path STARTS at top-centre like the other shapes
|
|
53
|
+
const SQUARE = polyPath([
|
|
54
|
+
[0, -0.2],
|
|
55
|
+
[0.2, -0.2],
|
|
56
|
+
[0.2, 0.2],
|
|
57
|
+
[-0.2, 0.2],
|
|
58
|
+
[-0.2, -0.2]
|
|
59
|
+
]);
|
|
60
|
+
const CYCLE: Path[] = [CIRCLE, TRIANGLE, SQUARE];
|
|
61
|
+
|
|
62
|
+
// low floor keeps sparse outlines possible while never degenerating
|
|
63
|
+
function morphN(d: number): number {
|
|
64
|
+
return Math.max(6, Math.round(34 * d));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const HOLD = 1.4;
|
|
68
|
+
const MORPH = 0.9;
|
|
69
|
+
const SEG = HOLD + MORPH;
|
|
70
|
+
|
|
71
|
+
// This state was tuned in inkform, which paints it through a blur +
|
|
72
|
+
// threshold "goo" filter; we draw plain circles instead, since `ctx.filter`
|
|
73
|
+
// and SVG filter refs are not safe to rely on across Chrome / Safari /
|
|
74
|
+
// Firefox. The dot GEOMETRY is identical either way — the threshold just
|
|
75
|
+
// yields a hard edge where a plain fill has an antialiased one, so these
|
|
76
|
+
// dots read a touch softer than inkform's. Don't "correct" for that by
|
|
77
|
+
// shrinking the radius: it makes the mark genuinely smaller than the tuning.
|
|
78
|
+
|
|
79
|
+
export const drawMorph: ModeDraw = (ctx, size, t, dark, o) => {
|
|
80
|
+
const K = CYCLE.length;
|
|
81
|
+
const tc = t % (SEG * K);
|
|
82
|
+
const k = Math.floor(tc / SEG);
|
|
83
|
+
const local = tc - k * SEG;
|
|
84
|
+
const m = local > HOLD ? smoothE((local - HOLD) / MORPH) : 0;
|
|
85
|
+
const sprd = o.spread ?? 1;
|
|
86
|
+
|
|
87
|
+
// blend the two shape PATHS at m, then measure the blended outline
|
|
88
|
+
const pA = CYCLE[k];
|
|
89
|
+
const pB = CYCLE[(k + 1) % K];
|
|
90
|
+
const M = 160;
|
|
91
|
+
const pts: Array<[number, number]> = [];
|
|
92
|
+
for (let i = 0; i < M; i++) {
|
|
93
|
+
const f = i / M;
|
|
94
|
+
const a = pA(f);
|
|
95
|
+
const b = pB(f);
|
|
96
|
+
pts.push([(a[0] + (b[0] - a[0]) * m) * sprd, (a[1] + (b[1] - a[1]) * m) * sprd]);
|
|
97
|
+
}
|
|
98
|
+
const L: number[] = [];
|
|
99
|
+
let total = 0;
|
|
100
|
+
for (let i = 0; i < M; i++) {
|
|
101
|
+
const a = pts[i];
|
|
102
|
+
const b = pts[(i + 1) % M];
|
|
103
|
+
const l = Math.hypot(b[0] - a[0], b[1] - a[1]);
|
|
104
|
+
L.push(l);
|
|
105
|
+
total += l;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// dot radius depends ONLY on rDot (the size knob); the count sets the
|
|
109
|
+
// gaps. Formed shapes breathe a little (uniform pulse).
|
|
110
|
+
const n = morphN(o.iconD ?? 1);
|
|
111
|
+
const re = (o.rDot ?? 0.021) * 1.35 * sprd;
|
|
112
|
+
const pulse = 1 + 0.02 * Math.sin(local * 3.1);
|
|
113
|
+
|
|
114
|
+
const dots: Dot[] = [];
|
|
115
|
+
const c2 = size / 2;
|
|
116
|
+
let seg = 0;
|
|
117
|
+
let acc = 0;
|
|
118
|
+
for (let k2 = 0; k2 < n; k2++) {
|
|
119
|
+
const target = (k2 / n) * total;
|
|
120
|
+
while (acc + L[seg] < target && seg < M - 1) {
|
|
121
|
+
acc += L[seg];
|
|
122
|
+
seg++;
|
|
123
|
+
}
|
|
124
|
+
const a = pts[seg];
|
|
125
|
+
const b = pts[(seg + 1) % M];
|
|
126
|
+
const f = L[seg] ? Math.min(1, (target - acc) / L[seg]) : 0;
|
|
127
|
+
const x = (a[0] + (b[0] - a[0]) * f) * pulse;
|
|
128
|
+
const y = (a[1] + (b[1] - a[1]) * f) * pulse;
|
|
129
|
+
dots.push({
|
|
130
|
+
x: c2 + x * size,
|
|
131
|
+
y: c2 + y * size,
|
|
132
|
+
z: 0,
|
|
133
|
+
r: Math.max(0.35, re * size),
|
|
134
|
+
white: 0.1
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
paint(ctx, dots, dark, o.rMin);
|
|
138
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Orbits: particles on tilted orbits — the "working" state. No nucleus
|
|
2
|
+
// (the tuned preset runs coreless): just ghost paths and the particles
|
|
3
|
+
// doing the work.
|
|
4
|
+
|
|
5
|
+
import type { Dot, ModeDraw } from './types';
|
|
6
|
+
import { hashD, makeProj, paint, radiusScale } from './core';
|
|
7
|
+
|
|
8
|
+
export const drawOrbits: ModeDraw = (ctx, size, t, dark, o) => {
|
|
9
|
+
const cx = size / 2;
|
|
10
|
+
const cy = size / 2;
|
|
11
|
+
const R = (size / 2) * 0.82;
|
|
12
|
+
const pt = makeProj(t * 0.12, 0.3, cx, cy, 1);
|
|
13
|
+
const rs = radiusScale(size, o.rsPow ?? 0.6);
|
|
14
|
+
|
|
15
|
+
const dots: Dot[] = [];
|
|
16
|
+
const orbitN = o.orbitN ?? 12;
|
|
17
|
+
const ghostN = o.ghostN ?? 40;
|
|
18
|
+
const particles = o.particles ?? 3;
|
|
19
|
+
|
|
20
|
+
// orbits: each a tilted circle — a ghost path + running particles
|
|
21
|
+
for (let orb = 0; orb < orbitN; orb++) {
|
|
22
|
+
const h1 = hashD(orb, 1.7);
|
|
23
|
+
const h2 = hashD(orb, 5.2);
|
|
24
|
+
const h3 = hashD(orb, 8.9);
|
|
25
|
+
const ro = R * (0.45 + 0.52 * h1);
|
|
26
|
+
const th = h1 * 2 * Math.PI;
|
|
27
|
+
const phi = Math.acos(2 * h2 - 1);
|
|
28
|
+
// orbit plane basis (u, v ⟂ normal n)
|
|
29
|
+
const nx = Math.sin(phi) * Math.cos(th);
|
|
30
|
+
const ny = Math.cos(phi);
|
|
31
|
+
const nz = Math.sin(phi) * Math.sin(th);
|
|
32
|
+
let ux = -ny;
|
|
33
|
+
let uy = nx;
|
|
34
|
+
const uz = 0;
|
|
35
|
+
const ul = Math.max(1e-6, Math.sqrt(ux * ux + uy * uy));
|
|
36
|
+
ux /= ul;
|
|
37
|
+
uy /= ul;
|
|
38
|
+
const vx = ny * uz - nz * uy;
|
|
39
|
+
const vy = nz * ux - nx * uz;
|
|
40
|
+
const vz = nx * uy - ny * ux;
|
|
41
|
+
const speed = (0.25 + 0.55 * h3) * (h3 > 0.5 ? 1 : -1);
|
|
42
|
+
|
|
43
|
+
// ghost path
|
|
44
|
+
for (let k = 0; k < ghostN; k++) {
|
|
45
|
+
const a = (k / ghostN) * 2 * Math.PI;
|
|
46
|
+
const [px, py, z] = pt(
|
|
47
|
+
(ux * Math.cos(a) + vx * Math.sin(a)) * ro,
|
|
48
|
+
(uy * Math.cos(a) + vy * Math.sin(a)) * ro,
|
|
49
|
+
(uz * Math.cos(a) + vz * Math.sin(a)) * ro
|
|
50
|
+
);
|
|
51
|
+
const depth = (z / ro + 1) / 2;
|
|
52
|
+
dots.push({
|
|
53
|
+
x: px,
|
|
54
|
+
y: py,
|
|
55
|
+
z,
|
|
56
|
+
r: (o.ghostR ?? 0.9) * rs,
|
|
57
|
+
white: 0.72,
|
|
58
|
+
a: (o.ghostA ?? 0.5) * (0.4 + 0.6 * depth)
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
// the particles doing the work
|
|
62
|
+
for (let m = 0; m < particles; m++) {
|
|
63
|
+
const a = t * speed + (m / particles) * 2 * Math.PI + h2 * 6;
|
|
64
|
+
const [px, py, z] = pt(
|
|
65
|
+
(ux * Math.cos(a) + vx * Math.sin(a)) * ro,
|
|
66
|
+
(uy * Math.cos(a) + vy * Math.sin(a)) * ro,
|
|
67
|
+
(uz * Math.cos(a) + vz * Math.sin(a)) * ro
|
|
68
|
+
);
|
|
69
|
+
const depth = (z / ro + 1) / 2;
|
|
70
|
+
dots.push({
|
|
71
|
+
x: px,
|
|
72
|
+
y: py,
|
|
73
|
+
z,
|
|
74
|
+
r: ((o.partR ?? 1.2) + (o.partRDepth ?? 1.6) * depth) * rs,
|
|
75
|
+
white: 0.3 - 0.22 * depth
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
paint(ctx, dots, dark, o.rMin);
|
|
80
|
+
};
|