kodeui 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +30 -2
- package/bin/kodeui.mjs +89 -0
- package/package.json +37 -4
- package/skill/kodeui/SKILL.md +105 -0
- package/skill/kodeui/assets/tokens.css +40 -0
- package/skill/kodeui/components/aurora-input/AuroraInput.tsx +153 -0
- package/skill/kodeui/components/aurora-input/aurora-input.css +218 -0
- package/skill/kodeui/components/aurora-input/index.ts +2 -0
- package/skill/kodeui/components/bloom-wall/BloomWall.tsx +90 -0
- package/skill/kodeui/components/bloom-wall/bloom-wall.css +10 -0
- package/skill/kodeui/components/bloom-wall/engine.ts +1022 -0
- package/skill/kodeui/components/bloom-wall/icons/icons-a.ts +818 -0
- package/skill/kodeui/components/bloom-wall/icons/icons-b.ts +827 -0
- package/skill/kodeui/components/bloom-wall/icons/index.ts +25 -0
- package/skill/kodeui/components/bloom-wall/icons/types.ts +8 -0
- package/skill/kodeui/components/bloom-wall/index.ts +12 -0
- package/skill/kodeui/components/bloom-wall/paint.ts +113 -0
- package/skill/kodeui/components/bloom-wall/palettes.ts +32 -0
- package/skill/kodeui/components/blur-in-text/BlurInText.tsx +53 -0
- package/skill/kodeui/components/blur-in-text/blur-in-text.css +14 -0
- package/skill/kodeui/components/blur-in-text/index.ts +2 -0
- package/skill/kodeui/components/glass-reveal/GlassReveal.tsx +108 -0
- package/skill/kodeui/components/glass-reveal/glass-reveal.css +126 -0
- package/skill/kodeui/components/glass-reveal/index.ts +2 -0
- package/skill/kodeui/components/glow-card/GlowCard.tsx +67 -0
- package/skill/kodeui/components/glow-card/glow-card.css +134 -0
- package/skill/kodeui/components/glow-card/index.ts +2 -0
- package/skill/kodeui/components/launch-chip/LaunchChip.tsx +180 -0
- package/skill/kodeui/components/launch-chip/icons.tsx +119 -0
- package/skill/kodeui/components/launch-chip/index.ts +3 -0
- package/skill/kodeui/components/launch-chip/launch-chip.css +345 -0
- package/skill/kodeui/components/ring-reveal/RingReveal.tsx +84 -0
- package/skill/kodeui/components/ring-reveal/index.ts +4 -0
- package/skill/kodeui/components/ring-reveal/ring-reveal.css +10 -0
- package/skill/kodeui/components/ring-reveal/ring.ts +298 -0
- package/skill/kodeui/components/rolling-text/RollingText.tsx +121 -0
- package/skill/kodeui/components/rolling-text/index.ts +4 -0
- package/skill/kodeui/components/rolling-text/roll.ts +94 -0
- package/skill/kodeui/components/rolling-text/rolling-text.css +43 -0
- package/skill/kodeui/components/use-live-transcript/index.ts +2 -0
- package/skill/kodeui/components/use-live-transcript/useLiveTranscript.ts +215 -0
- package/skill/kodeui/components/voice-input/VoiceInput.tsx +273 -0
- package/skill/kodeui/components/voice-input/icons.tsx +27 -0
- package/skill/kodeui/components/voice-input/index.ts +4 -0
- package/skill/kodeui/components/voice-input/useVoiceRecorder.ts +289 -0
- package/skill/kodeui/components/voice-input/voice-input.css +34 -0
- package/skill/kodeui/components/voice-note/VoiceNote.tsx +170 -0
- package/skill/kodeui/components/voice-note/index.ts +3 -0
- package/skill/kodeui/components/voice-note/noteFile.ts +25 -0
- package/skill/kodeui/components/voice-note/voice-note.css +45 -0
- package/skill/kodeui/references/aurora-input.md +44 -0
- package/skill/kodeui/references/bloom-wall.md +59 -0
- package/skill/kodeui/references/blur-in-text.md +17 -0
- package/skill/kodeui/references/frameworks.md +46 -0
- package/skill/kodeui/references/glass-reveal.md +40 -0
- package/skill/kodeui/references/glow-card.md +48 -0
- package/skill/kodeui/references/launch-chip.md +37 -0
- package/skill/kodeui/references/recipes.md +77 -0
- package/skill/kodeui/references/ring-reveal.md +35 -0
- package/skill/kodeui/references/rolling-text.md +19 -0
- package/skill/kodeui/references/theming.md +45 -0
- package/skill/kodeui/references/use-live-transcript.md +28 -0
- package/skill/kodeui/references/voice-input.md +60 -0
- package/skill/kodeui/references/voice-note.md +22 -0
- package/skill/kodeui/scripts/add.mjs +192 -0
- package/skill/kodeui/scripts/manifest.json +92 -0
|
@@ -0,0 +1,818 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Bloom Wall icons, set A: daisy, tree rings, fireflies, nautilus, dandelion, wave, honeycomb, clover.
|
|
3
|
+
*
|
|
4
|
+
* Every icon draws around (0, 0) inside radius r. It starts with the halo, keeps its lines thin
|
|
5
|
+
* (about r * 0.022), drops detail below r 42 and again below r 18, and batches its strokes into
|
|
6
|
+
* a few alpha bands, so a wall of ~150 tiles stays at 60 fps. Colours only come from the tint
|
|
7
|
+
* (`grad`, `rampColor`, `t.colors`), so a sleeping tile fades to moss grey.
|
|
8
|
+
*/
|
|
9
|
+
import { TAU, bucket, clamp, grad, halo, hashA, hashB, rampColor, smoothstep } from '../paint';
|
|
10
|
+
import type { IconDraw } from './types';
|
|
11
|
+
|
|
12
|
+
const frac = (x: number) => x - Math.floor(x);
|
|
13
|
+
/** The study's hairline: r * 0.022, kept between 0.65 and 1.5 px. */
|
|
14
|
+
const thin = (r: number) => clamp(r * 0.022, 0.65, 1.5);
|
|
15
|
+
|
|
16
|
+
/* A tiny rotation helper for building rotated shapes into one path without save/restore. */
|
|
17
|
+
let RC = 1;
|
|
18
|
+
let RS = 0;
|
|
19
|
+
const turnTo = (a: number) => { RC = Math.cos(a); RS = Math.sin(a); };
|
|
20
|
+
const X = (x: number, y: number) => x * RC - y * RS;
|
|
21
|
+
const Y = (x: number, y: number) => x * RS + y * RC;
|
|
22
|
+
|
|
23
|
+
/* ------------------------------------------------------------------ daisy */
|
|
24
|
+
|
|
25
|
+
/** One petal along the current turn: base on the disc, rounded (or notched) tip at `len`. */
|
|
26
|
+
function petal(ctx: CanvasRenderingContext2D, base: number, len: number, w: number, notch: boolean) {
|
|
27
|
+
const mid = base + (len - base) * 0.22;
|
|
28
|
+
const sx = len - w * 1.3;
|
|
29
|
+
const tx = len - w * 0.18;
|
|
30
|
+
ctx.moveTo(X(base, 0), Y(base, 0));
|
|
31
|
+
ctx.bezierCurveTo(X(mid, -w), Y(mid, -w), X(sx, -w * 1.08), Y(sx, -w * 1.08), X(tx, -w * 0.5), Y(tx, -w * 0.5));
|
|
32
|
+
if (notch) {
|
|
33
|
+
const nx = len - w * 0.24;
|
|
34
|
+
ctx.quadraticCurveTo(X(len + w * 0.08, -w * 0.22), Y(len + w * 0.08, -w * 0.22), X(nx, 0), Y(nx, 0));
|
|
35
|
+
ctx.quadraticCurveTo(X(len + w * 0.08, w * 0.22), Y(len + w * 0.08, w * 0.22), X(tx, w * 0.5), Y(tx, w * 0.5));
|
|
36
|
+
} else {
|
|
37
|
+
ctx.quadraticCurveTo(X(len + w * 0.3, 0), Y(len + w * 0.3, 0), X(tx, w * 0.5), Y(tx, w * 0.5));
|
|
38
|
+
}
|
|
39
|
+
ctx.bezierCurveTo(X(sx, w * 1.08), Y(sx, w * 1.08), X(mid, w), Y(mid, w), X(base, 0), Y(base, 0));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const daisy: IconDraw = (ctx, r, time, k, t) => {
|
|
43
|
+
halo(ctx, r, t, k, 0.22);
|
|
44
|
+
const layers = r < 18 ? 1 : r < 42 ? 2 : 3;
|
|
45
|
+
const count = r < 18 ? 9 : r < 42 ? 12 : 14;
|
|
46
|
+
const step = TAU / count;
|
|
47
|
+
const disc = r * (r < 18 ? 0.22 : 0.19);
|
|
48
|
+
const notch = r >= 42;
|
|
49
|
+
ctx.save();
|
|
50
|
+
ctx.rotate(time * 0.17);
|
|
51
|
+
ctx.lineWidth = thin(r);
|
|
52
|
+
ctx.lineJoin = 'round';
|
|
53
|
+
// back layers first so the front ring of petals sits on top
|
|
54
|
+
for (let L = layers - 1; L >= 0; L--) {
|
|
55
|
+
const f = layers === 1 ? 0 : L / (layers - 1);
|
|
56
|
+
const reach = r * (0.93 - 0.17 * f) * (0.97 + 0.04 * k);
|
|
57
|
+
const w = r * (0.105 - 0.012 * f) * (0.94 + 0.1 * k);
|
|
58
|
+
const offset = (L * step) / layers;
|
|
59
|
+
for (let band = 0; band < 2; band++) {
|
|
60
|
+
const a = (0.3 + 0.58 * (1 - f * 0.5)) * (band ? 1 : 0.62) * (0.86 + 0.14 * k);
|
|
61
|
+
ctx.strokeStyle = grad(t, f * 0.85 + (band ? 0 : 0.15), a);
|
|
62
|
+
ctx.beginPath();
|
|
63
|
+
for (let p = 0; p < count; p++) {
|
|
64
|
+
const breathe = Math.sin(time * 1.25 + p * 0.95 + L * 1.3);
|
|
65
|
+
if ((breathe > 0 ? 1 : 0) !== band) continue;
|
|
66
|
+
turnTo(offset + p * step);
|
|
67
|
+
petal(ctx, disc * 0.94, reach * (0.93 + 0.07 * breathe), w * (0.95 + 0.06 * breathe), notch);
|
|
68
|
+
}
|
|
69
|
+
ctx.stroke();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// the centre: a disc of florets in a sunflower spiral
|
|
73
|
+
ctx.fillStyle = grad(t, 0, r < 18 ? 0.85 : 0.14 + 0.08 * k);
|
|
74
|
+
ctx.beginPath(); ctx.arc(0, 0, disc, 0, TAU); ctx.fill();
|
|
75
|
+
if (r >= 18) {
|
|
76
|
+
const n = r < 42 ? 13 : 34;
|
|
77
|
+
const dot = Math.max(0.55, disc * (r < 42 ? 0.12 : 0.085));
|
|
78
|
+
for (let band = 0; band < 2; band++) {
|
|
79
|
+
ctx.fillStyle = band ? grad(t, 0, 0.95) : grad(t, 0.55, 0.62 + 0.2 * k);
|
|
80
|
+
ctx.beginPath();
|
|
81
|
+
for (let i = 0; i < n; i++) {
|
|
82
|
+
const u = (i + 0.6) / n;
|
|
83
|
+
if ((u < 0.45 ? 1 : 0) !== band) continue;
|
|
84
|
+
const rr = disc * 0.8 * Math.sqrt(u);
|
|
85
|
+
const a = i * 2.39996 + time * 0.35;
|
|
86
|
+
const x = Math.cos(a) * rr, y = Math.sin(a) * rr;
|
|
87
|
+
ctx.moveTo(x + dot, y); ctx.arc(x, y, dot, 0, TAU);
|
|
88
|
+
}
|
|
89
|
+
ctx.fill();
|
|
90
|
+
}
|
|
91
|
+
ctx.strokeStyle = grad(t, 0.25, 0.7 + 0.2 * k);
|
|
92
|
+
ctx.beginPath(); ctx.arc(0, 0, disc, 0, TAU); ctx.stroke();
|
|
93
|
+
}
|
|
94
|
+
ctx.restore();
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/* ------------------------------------------------------------- tree rings */
|
|
98
|
+
|
|
99
|
+
const CRACK = -0.95; // where the crack runs in from the bark
|
|
100
|
+
const barkShape = (a: number) => 1 + 0.032 * Math.sin(3 * a + 0.6) + 0.02 * Math.sin(5 * a + 2.1) + 0.01 * Math.sin(9 * a + 0.3);
|
|
101
|
+
/** Per detail level: cos, sin and bark wobble on an even angle grid that starts at the crack. */
|
|
102
|
+
const RING_GRID: Record<number, { c: Float64Array; s: Float64Array; w: Float64Array }> = {};
|
|
103
|
+
function ringGrid(n: number) {
|
|
104
|
+
let g = RING_GRID[n];
|
|
105
|
+
if (g) return g;
|
|
106
|
+
g = { c: new Float64Array(n + 1), s: new Float64Array(n + 1), w: new Float64Array(n + 1) };
|
|
107
|
+
for (let j = 0; j <= n; j++) {
|
|
108
|
+
const a = CRACK + (j / n) * TAU;
|
|
109
|
+
g.c[j] = Math.cos(a); g.s[j] = Math.sin(a); g.w[j] = barkShape(a) - 1;
|
|
110
|
+
}
|
|
111
|
+
return (RING_GRID[n] = g);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* One growth ring around (cx, cy) at mean radius `rad`, its wobble scaled by `wob`,
|
|
116
|
+
* open by the half-angle `gap` on both sides of the crack (closed when gap is 0).
|
|
117
|
+
*/
|
|
118
|
+
function ring(ctx: CanvasRenderingContext2D, n: number, cx: number, cy: number, rad: number, wob: number, gap: number, stride: number) {
|
|
119
|
+
const g = ringGrid(n);
|
|
120
|
+
if (gap <= 0) {
|
|
121
|
+
ctx.moveTo(cx + g.c[0] * rad * (1 + g.w[0] * wob), cy + g.s[0] * rad * (1 + g.w[0] * wob));
|
|
122
|
+
for (let j = stride; j < n; j += stride) {
|
|
123
|
+
const p = rad * (1 + g.w[j] * wob);
|
|
124
|
+
ctx.lineTo(cx + g.c[j] * p, cy + g.s[j] * p);
|
|
125
|
+
}
|
|
126
|
+
ctx.closePath();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const edge = (a: number, first: boolean) => {
|
|
130
|
+
const p = rad * (1 + (barkShape(a) - 1) * wob);
|
|
131
|
+
if (first) ctx.moveTo(cx + Math.cos(a) * p, cy + Math.sin(a) * p);
|
|
132
|
+
else ctx.lineTo(cx + Math.cos(a) * p, cy + Math.sin(a) * p);
|
|
133
|
+
};
|
|
134
|
+
edge(CRACK + gap, true);
|
|
135
|
+
const j0 = Math.floor((gap / TAU) * n) + 1, j1 = Math.ceil(((TAU - gap) / TAU) * n) - 1;
|
|
136
|
+
for (let j = j0; j <= j1; j += j === j1 ? 1 : Math.min(stride, j1 - j)) {
|
|
137
|
+
const p = rad * (1 + g.w[j] * wob);
|
|
138
|
+
ctx.lineTo(cx + g.c[j] * p, cy + g.s[j] * p);
|
|
139
|
+
}
|
|
140
|
+
edge(CRACK + TAU - gap, false);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const treeRings: IconDraw = (ctx, r, time, k, t) => {
|
|
144
|
+
halo(ctx, r, t, k, 0.24);
|
|
145
|
+
const R = r * (0.9 + 0.03 * k);
|
|
146
|
+
const n = r < 18 ? 4 : r < 42 ? 6 : 9;
|
|
147
|
+
const seg = r < 18 ? 24 : r < 42 ? 36 : 48;
|
|
148
|
+
const flow = time * 0.12;
|
|
149
|
+
const grow = frac(flow);
|
|
150
|
+
const born = Math.floor(flow);
|
|
151
|
+
const crackIn = 0.36;
|
|
152
|
+
const px = -r * 0.07, py = r * 0.06; // the pith sits a little off centre, as in a real trunk
|
|
153
|
+
const band = (R / n) * 0.42;
|
|
154
|
+
const crackHalf = (u: number) => (u <= crackIn ? 0 : R * 0.065 * smoothstep(crackIn, 1, u));
|
|
155
|
+
ctx.save();
|
|
156
|
+
ctx.rotate(0.12 * Math.sin(time * 0.21));
|
|
157
|
+
// the bark outline, lightly filled
|
|
158
|
+
ctx.beginPath();
|
|
159
|
+
ring(ctx, seg, 0, 0, R, 1, 0, 1);
|
|
160
|
+
ctx.fillStyle = grad(t, 1, 0.08);
|
|
161
|
+
ctx.fill();
|
|
162
|
+
// growth rings: each band moves outward from the pith and melts into the bark.
|
|
163
|
+
// A ring with u < 1 always sits inside the bark (same wobble, smaller), so no clip is needed.
|
|
164
|
+
const uMax = 1 - band / R - 0.015;
|
|
165
|
+
ctx.lineWidth = band;
|
|
166
|
+
for (let b = 0; b < 4; b++) {
|
|
167
|
+
const f = (b + 0.5) / 4;
|
|
168
|
+
ctx.strokeStyle = grad(t, 1 - f, 0.2 + 0.68 * f * (0.86 + 0.14 * k));
|
|
169
|
+
ctx.beginPath();
|
|
170
|
+
for (let i = 0; i <= n; i++) {
|
|
171
|
+
const u = ((i + grow) / n) * uMax;
|
|
172
|
+
if (u > uMax) continue;
|
|
173
|
+
const v = smoothstep(0, 0.2, u) * (1 - smoothstep(uMax - 0.16, uMax, u)) * (0.45 + 0.55 * hashA((i - born) * 3.71));
|
|
174
|
+
if (bucket(v) !== b) continue;
|
|
175
|
+
const rad = Math.max(0.5, R * u);
|
|
176
|
+
const gap = u > crackIn ? (crackHalf(u) + band * 0.5) / rad : 0;
|
|
177
|
+
ring(ctx, seg, px * (1 - u), py * (1 - u), rad, 0.3 + 0.7 * u, gap, u < 0.45 ? 2 : 1);
|
|
178
|
+
}
|
|
179
|
+
ctx.stroke();
|
|
180
|
+
}
|
|
181
|
+
// thin early-wood lines between the bands
|
|
182
|
+
if (r >= 42) {
|
|
183
|
+
ctx.lineWidth = thin(r) * 0.8;
|
|
184
|
+
ctx.strokeStyle = grad(t, 0.5, 0.3 + 0.12 * k);
|
|
185
|
+
ctx.beginPath();
|
|
186
|
+
for (let i = 0; i <= n; i++) {
|
|
187
|
+
const u = ((i + grow + 0.5) / n) * uMax;
|
|
188
|
+
if (u > uMax || u < 0.08) continue;
|
|
189
|
+
const rad = R * u;
|
|
190
|
+
ring(ctx, seg, px * (1 - u), py * (1 - u), rad, 0.3 + 0.7 * u, u > crackIn ? crackHalf(u) / rad : 0, u < 0.45 ? 2 : 1);
|
|
191
|
+
}
|
|
192
|
+
ctx.stroke();
|
|
193
|
+
}
|
|
194
|
+
// the crack: two jagged edges meeting at its tip
|
|
195
|
+
if (r >= 18) {
|
|
196
|
+
ctx.lineWidth = thin(r) * 0.85;
|
|
197
|
+
ctx.strokeStyle = grad(t, 0, 0.5 + 0.25 * k);
|
|
198
|
+
ctx.beginPath();
|
|
199
|
+
for (let side = -1; side <= 1; side += 2) {
|
|
200
|
+
for (let j = 0; j <= 5; j++) {
|
|
201
|
+
const u = 0.985 - (j / 5) * (0.985 - crackIn);
|
|
202
|
+
const jag = (hashB(j * 5.3 + side) - 0.5) * 0.06;
|
|
203
|
+
const a = CRACK + side * (crackHalf(u) / (R * u)) + jag;
|
|
204
|
+
const cx = px * (1 - u), cy = py * (1 - u);
|
|
205
|
+
const rr = R * u * (1 + (barkShape(a) - 1) * (0.3 + 0.7 * u));
|
|
206
|
+
j ? ctx.lineTo(cx + Math.cos(a) * rr, cy + Math.sin(a) * rr) : ctx.moveTo(cx + Math.cos(a) * rr, cy + Math.sin(a) * rr);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
ctx.stroke();
|
|
210
|
+
}
|
|
211
|
+
// the pith and the bark
|
|
212
|
+
ctx.fillStyle = grad(t, 0, 0.92);
|
|
213
|
+
ctx.beginPath(); ctx.arc(px, py, Math.max(0.8, r * 0.035), 0, TAU); ctx.fill();
|
|
214
|
+
ctx.lineWidth = clamp(r * 0.03, 0.8, 2);
|
|
215
|
+
ctx.strokeStyle = grad(t, 0, 0.6 + 0.3 * k);
|
|
216
|
+
ctx.beginPath();
|
|
217
|
+
ring(ctx, seg, 0, 0, R, 1, 0, 1);
|
|
218
|
+
ctx.stroke();
|
|
219
|
+
ctx.restore();
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
/* -------------------------------------------------------------- fireflies */
|
|
223
|
+
|
|
224
|
+
/* Each firefly loops loosely around its own home: a wide circle plus a faster
|
|
225
|
+
counter-turning one, which makes the little loops of a real firefly's flight.
|
|
226
|
+
Its light blinks, so the trail it leaves is a dashed streak, like a long-exposure photo. */
|
|
227
|
+
interface Fly { hx: number; hy: number; a: number; w: number; p: number; b: number; q: number; blink: number; bp: number }
|
|
228
|
+
const FLY_HOMES = [[-0.32, -0.34], [0.36, -0.3], [0.02, 0.0], [-0.4, 0.22], [0.42, 0.22]];
|
|
229
|
+
const FLIES: Fly[] = FLY_HOMES.map(([hx, hy], i) => ({
|
|
230
|
+
hx, hy,
|
|
231
|
+
a: 0.16 + 0.05 * hashA(i * 7.31 + 0.1),
|
|
232
|
+
w: (0.8 + 0.3 * hashA(i * 7.31 + 0.2)) * (i % 2 ? -1 : 1),
|
|
233
|
+
p: TAU * hashA(i * 7.31 + 0.3),
|
|
234
|
+
b: 0.085 + 0.025 * hashA(i * 7.31 + 0.5),
|
|
235
|
+
q: TAU * hashA(i * 7.31 + 0.6),
|
|
236
|
+
blink: 2.4 + 1.0 * hashB(i * 2.7 + 1.5),
|
|
237
|
+
bp: TAU * hashB(i * 5.1 + 2.5),
|
|
238
|
+
}));
|
|
239
|
+
const flyX = (f: Fly, s: number) => f.hx + f.a * Math.cos(f.w * s + f.p) + f.b * Math.cos(-2.6 * f.w * s + f.q);
|
|
240
|
+
const flyY = (f: Fly, s: number) => f.hy + f.a * 0.8 * Math.sin(f.w * s + f.p) + f.b * Math.sin(-2.6 * f.w * s + f.q);
|
|
241
|
+
/** 0..1: how lit a firefly is at time s (on for a little over half of each blink). */
|
|
242
|
+
const flyLight = (f: Fly, s: number) => smoothstep(-0.25, 0.55, Math.sin(s * f.blink + f.bp));
|
|
243
|
+
const TRAIL = new Float64Array(3 * 48);
|
|
244
|
+
|
|
245
|
+
const fireflies: IconDraw = (ctx, r, time, k, t) => {
|
|
246
|
+
halo(ctx, r, t, k, 0.2);
|
|
247
|
+
const count = r < 18 ? 3 : r < 42 ? 4 : 5;
|
|
248
|
+
const m = r < 18 ? 10 : r < 42 ? 22 : 40;
|
|
249
|
+
const span = 3.2;
|
|
250
|
+
const lw = thin(r);
|
|
251
|
+
ctx.save();
|
|
252
|
+
ctx.lineCap = 'round';
|
|
253
|
+
ctx.lineJoin = 'round';
|
|
254
|
+
// a few grass blades at the bottom: where fireflies live
|
|
255
|
+
if (r >= 18) {
|
|
256
|
+
const blades = r < 42 ? 4 : 6;
|
|
257
|
+
ctx.lineWidth = lw;
|
|
258
|
+
ctx.strokeStyle = grad(t, 1, 0.26 + 0.08 * k);
|
|
259
|
+
ctx.beginPath();
|
|
260
|
+
for (let i = 0; i < blades; i++) {
|
|
261
|
+
const u = i / (blades - 1);
|
|
262
|
+
const bx = r * (-0.48 + u * 0.96);
|
|
263
|
+
const by = r * (0.9 - 0.3 * (u - 0.5) * (u - 0.5));
|
|
264
|
+
const h = r * (0.22 + 0.2 * hashA(i * 1.9 + 0.4));
|
|
265
|
+
const lean = (u - 0.5) * 0.7 + 0.14 * Math.sin(time * 0.8 + i * 1.3);
|
|
266
|
+
ctx.moveTo(bx, by);
|
|
267
|
+
ctx.quadraticCurveTo(bx + lean * h * 0.15, by - h * 0.65, bx + lean * h, by - h);
|
|
268
|
+
}
|
|
269
|
+
ctx.stroke();
|
|
270
|
+
}
|
|
271
|
+
// light trails: one stroke per alpha band for all fireflies; dark stretches lift the pen
|
|
272
|
+
for (let b = 0; b < 4; b++) {
|
|
273
|
+
const f = (b + 0.5) / 4;
|
|
274
|
+
ctx.lineWidth = lw * (0.8 + 0.5 * f);
|
|
275
|
+
ctx.strokeStyle = grad(t, 1 - f, (0.2 + 0.76 * f) * (0.86 + 0.14 * k));
|
|
276
|
+
ctx.beginPath();
|
|
277
|
+
for (let i = 0; i < count; i++) {
|
|
278
|
+
const fly = FLIES[i];
|
|
279
|
+
for (let j = 0; j <= m; j++) {
|
|
280
|
+
const sj = time - (j / m) * span;
|
|
281
|
+
TRAIL[3 * j] = flyX(fly, sj) * r;
|
|
282
|
+
TRAIL[3 * j + 1] = flyY(fly, sj) * r;
|
|
283
|
+
TRAIL[3 * j + 2] = flyLight(fly, sj);
|
|
284
|
+
}
|
|
285
|
+
let pen = false;
|
|
286
|
+
for (let j = 0; j < m; j++) {
|
|
287
|
+
const lit = Math.min(TRAIL[3 * j + 2], TRAIL[3 * j + 5]);
|
|
288
|
+
const fade = 1 - j / m;
|
|
289
|
+
if (lit < 0.3 || bucket((0.12 + 0.88 * fade) * (0.6 + 0.4 * lit)) !== b) { pen = false; continue; }
|
|
290
|
+
if (!pen) { ctx.moveTo(TRAIL[3 * j], TRAIL[3 * j + 1]); pen = true; }
|
|
291
|
+
ctx.lineTo(TRAIL[3 * j + 3], TRAIL[3 * j + 4]);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
ctx.stroke();
|
|
295
|
+
}
|
|
296
|
+
// the glow: one soft gradient shared by every firefly (none on tiny tiles)
|
|
297
|
+
if (r >= 18) {
|
|
298
|
+
const g = ctx.createRadialGradient(0, 0, 0, 0, 0, 1);
|
|
299
|
+
g.addColorStop(0, rampColor(t, 5, 0.6));
|
|
300
|
+
g.addColorStop(0.35, grad(t, 0, 0.22));
|
|
301
|
+
g.addColorStop(1, rampColor(t, 5, 0));
|
|
302
|
+
ctx.fillStyle = g;
|
|
303
|
+
const base = ctx.globalAlpha;
|
|
304
|
+
for (let i = 0; i < count; i++) {
|
|
305
|
+
const fly = FLIES[i];
|
|
306
|
+
const light = flyLight(fly, time);
|
|
307
|
+
if (light < 0.05) continue;
|
|
308
|
+
const x = flyX(fly, time) * r, y = flyY(fly, time) * r;
|
|
309
|
+
const rad = r * (0.14 + 0.1 * light);
|
|
310
|
+
ctx.globalAlpha = base * light * (0.75 + 0.3 * k) * (0.35 + 0.65 * t.haloStrength);
|
|
311
|
+
ctx.translate(x, y);
|
|
312
|
+
ctx.scale(rad, rad);
|
|
313
|
+
ctx.beginPath(); ctx.arc(0, 0, 1, 0, TAU); ctx.fill();
|
|
314
|
+
ctx.scale(1 / rad, 1 / rad);
|
|
315
|
+
ctx.translate(-x, -y);
|
|
316
|
+
}
|
|
317
|
+
ctx.globalAlpha = base;
|
|
318
|
+
}
|
|
319
|
+
// bodies: a bright core and a small disc of light, in two groups (lit / dark)
|
|
320
|
+
for (let g = 0; g < 2; g++) {
|
|
321
|
+
for (let layer = 0; layer < 2; layer++) {
|
|
322
|
+
ctx.fillStyle = layer === 0 ? grad(t, 0, (g ? 0.4 : 0.14) * (0.85 + 0.2 * k)) : grad(t, 0, g ? 1 : 0.5);
|
|
323
|
+
ctx.beginPath();
|
|
324
|
+
for (let i = 0; i < count; i++) {
|
|
325
|
+
const fly = FLIES[i];
|
|
326
|
+
const light = flyLight(fly, time);
|
|
327
|
+
if ((light > 0.5 ? 1 : 0) !== g) continue;
|
|
328
|
+
const x = flyX(fly, time) * r, y = flyY(fly, time) * r;
|
|
329
|
+
const rad = layer === 0 ? Math.max(1.8, r * (0.055 + 0.035 * light)) : Math.max(1, r * 0.038);
|
|
330
|
+
ctx.moveTo(x + rad, y); ctx.arc(x, y, rad, 0, TAU);
|
|
331
|
+
}
|
|
332
|
+
ctx.fill();
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
ctx.restore();
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
/* --------------------------------------------------------------- nautilus */
|
|
339
|
+
|
|
340
|
+
const NB = 0.175; // log-spiral growth: about x3 per turn, like a real shell
|
|
341
|
+
const nautX = (a: number) => Math.exp(NB * a) * Math.cos(a);
|
|
342
|
+
const nautY = (a: number) => Math.exp(NB * a) * Math.sin(a);
|
|
343
|
+
// the shell's own box (unit size), so it can turn around its visual centre
|
|
344
|
+
const NAUT = (() => {
|
|
345
|
+
let x0 = Infinity, x1 = -Infinity, y0 = Infinity, y1 = -Infinity;
|
|
346
|
+
for (let i = 0; i <= 400; i++) {
|
|
347
|
+
const a = -TAU + (i / 400) * TAU;
|
|
348
|
+
const x = nautX(a), y = nautY(a);
|
|
349
|
+
x0 = Math.min(x0, x); x1 = Math.max(x1, x); y0 = Math.min(y0, y); y1 = Math.max(y1, y);
|
|
350
|
+
}
|
|
351
|
+
y1 = Math.max(y1, 0.12);
|
|
352
|
+
return { cx: (x0 + x1) / 2, cy: (y0 + y1) / 2, half: Math.max(x1 - x0, y1 - y0) / 2 };
|
|
353
|
+
})();
|
|
354
|
+
|
|
355
|
+
const nautilus: IconDraw = (ctx, r, time, k, t) => {
|
|
356
|
+
halo(ctx, r, t, k, 0.24);
|
|
357
|
+
const S = (r * (0.9 + 0.03 * k)) / NAUT.half;
|
|
358
|
+
const per = r < 18 ? 7 : r < 42 ? 10 : 13;
|
|
359
|
+
const D = TAU / per;
|
|
360
|
+
const live = -0.6 * Math.PI; // the open living chamber runs from here to the aperture
|
|
361
|
+
const amin = r < 18 ? -2.3 * Math.PI : r < 42 ? -3.1 * Math.PI : -3.8 * Math.PI;
|
|
362
|
+
const da = r < 18 ? 0.34 : r < 42 ? 0.2 : 0.13;
|
|
363
|
+
const bow = 0.28;
|
|
364
|
+
const px = (a: number) => (nautX(a) - NAUT.cx) * S;
|
|
365
|
+
const py = (a: number) => (nautY(a) - NAUT.cy) * S;
|
|
366
|
+
// a septum (chamber wall) from the outer whorl at angle a to the whorl inside it, bowed backwards
|
|
367
|
+
const septum = (a: number, reverse: boolean) => {
|
|
368
|
+
const ro = Math.exp(NB * a), ri = Math.exp(NB * (a - TAU));
|
|
369
|
+
const rm = (ro + ri) / 2, am = a - bow;
|
|
370
|
+
const cxp = (Math.cos(am) * rm - NAUT.cx) * S, cyp = (Math.sin(am) * rm - NAUT.cy) * S;
|
|
371
|
+
if (reverse) ctx.quadraticCurveTo(cxp, cyp, px(a), py(a));
|
|
372
|
+
else ctx.quadraticCurveTo(cxp, cyp, px(a - TAU), py(a - TAU));
|
|
373
|
+
};
|
|
374
|
+
ctx.save();
|
|
375
|
+
ctx.rotate(time * 0.1);
|
|
376
|
+
ctx.lineJoin = 'round';
|
|
377
|
+
// the shell silhouette (outer whorl + aperture), lightly filled
|
|
378
|
+
ctx.beginPath();
|
|
379
|
+
for (let a = -TAU; a < 0; a += da) a === -TAU ? ctx.moveTo(px(a), py(a)) : ctx.lineTo(px(a), py(a));
|
|
380
|
+
ctx.lineTo(px(0), py(0));
|
|
381
|
+
ctx.quadraticCurveTo((0.68 - NAUT.cx) * S, (0.26 - NAUT.cy) * S, px(-TAU), py(-TAU));
|
|
382
|
+
ctx.fillStyle = grad(t, 1, 0.08);
|
|
383
|
+
ctx.fill();
|
|
384
|
+
// the living chamber glows softly
|
|
385
|
+
ctx.beginPath();
|
|
386
|
+
ctx.moveTo(px(live), py(live));
|
|
387
|
+
for (let a = live + da; a < 0; a += da) ctx.lineTo(px(a), py(a));
|
|
388
|
+
ctx.lineTo(px(0), py(0));
|
|
389
|
+
ctx.quadraticCurveTo((0.68 - NAUT.cx) * S, (0.26 - NAUT.cy) * S, px(-TAU), py(-TAU));
|
|
390
|
+
for (let a = -TAU + da; a < live - TAU; a += da) ctx.lineTo(px(a), py(a));
|
|
391
|
+
ctx.lineTo(px(live - TAU), py(live - TAU));
|
|
392
|
+
septum(live, true);
|
|
393
|
+
ctx.fillStyle = grad(t, 0, 0.12 + 0.06 * k);
|
|
394
|
+
ctx.fill();
|
|
395
|
+
// chambers: every other one filled, a light travelling along them = the stripes
|
|
396
|
+
const chambers = Math.floor((live - amin) / D);
|
|
397
|
+
for (let b = 0; b < 4; b++) {
|
|
398
|
+
const f = (b + 0.5) / 4;
|
|
399
|
+
ctx.fillStyle = grad(t, 1 - f, (0.16 + 0.62 * f) * (0.86 + 0.14 * k));
|
|
400
|
+
ctx.beginPath();
|
|
401
|
+
for (let j = 0; j < chambers; j += 2) {
|
|
402
|
+
const v = 0.5 + 0.5 * Math.sin(j * 0.55 + time * 1.4);
|
|
403
|
+
const depth = 1 - j / Math.max(1, chambers);
|
|
404
|
+
if (bucket(v * (0.45 + 0.55 * depth)) !== b) continue;
|
|
405
|
+
const a1 = live - j * D, a0 = a1 - D;
|
|
406
|
+
const sub = Math.max(2, Math.ceil(D / da));
|
|
407
|
+
ctx.moveTo(px(a0), py(a0));
|
|
408
|
+
for (let q = 1; q <= sub; q++) { const a = a0 + (q / sub) * D; ctx.lineTo(px(a), py(a)); }
|
|
409
|
+
septum(a1, false);
|
|
410
|
+
for (let q = sub - 1; q >= 0; q--) { const a = a0 - TAU + (q / sub) * D; ctx.lineTo(px(a), py(a)); }
|
|
411
|
+
septum(a0, true);
|
|
412
|
+
ctx.closePath();
|
|
413
|
+
}
|
|
414
|
+
ctx.fill();
|
|
415
|
+
}
|
|
416
|
+
// chamber walls
|
|
417
|
+
ctx.lineWidth = thin(r) * 0.85;
|
|
418
|
+
ctx.strokeStyle = grad(t, 0.6, 0.42 + 0.2 * k);
|
|
419
|
+
ctx.beginPath();
|
|
420
|
+
for (let j = 0; j <= chambers; j++) {
|
|
421
|
+
const a = live - j * D;
|
|
422
|
+
ctx.moveTo(px(a), py(a));
|
|
423
|
+
septum(a, false);
|
|
424
|
+
}
|
|
425
|
+
ctx.stroke();
|
|
426
|
+
// the spiral itself, out to the aperture
|
|
427
|
+
ctx.lineWidth = thin(r) * 1.15;
|
|
428
|
+
ctx.strokeStyle = grad(t, 0, 0.72 + 0.22 * k);
|
|
429
|
+
ctx.beginPath();
|
|
430
|
+
const start = amin - TAU;
|
|
431
|
+
ctx.moveTo(px(start), py(start));
|
|
432
|
+
for (let a = start + da; a < 0; a += da) ctx.lineTo(px(a), py(a));
|
|
433
|
+
ctx.lineTo(px(0), py(0));
|
|
434
|
+
ctx.quadraticCurveTo((0.68 - NAUT.cx) * S, (0.26 - NAUT.cy) * S, px(-TAU), py(-TAU));
|
|
435
|
+
ctx.stroke();
|
|
436
|
+
ctx.restore();
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
/* -------------------------------------------------------------- dandelion */
|
|
440
|
+
|
|
441
|
+
const SPHERES: Record<number, Float32Array> = {};
|
|
442
|
+
/** Evenly spread points on a unit sphere (golden-angle spiral), cached per count. */
|
|
443
|
+
function sphere(n: number) {
|
|
444
|
+
let s = SPHERES[n];
|
|
445
|
+
if (s) return s;
|
|
446
|
+
s = new Float32Array(n * 3);
|
|
447
|
+
for (let i = 0; i < n; i++) {
|
|
448
|
+
const y = 1 - (2 * (i + 0.5)) / n;
|
|
449
|
+
const rad = Math.sqrt(1 - y * y);
|
|
450
|
+
const a = i * 2.39996;
|
|
451
|
+
s[3 * i] = Math.cos(a) * rad; s[3 * i + 1] = y; s[3 * i + 2] = Math.sin(a) * rad;
|
|
452
|
+
}
|
|
453
|
+
return (SPHERES[n] = s);
|
|
454
|
+
}
|
|
455
|
+
const FAN3 = [-0.75, 0, 0.75].map((a) => [Math.cos(a), Math.sin(a)]);
|
|
456
|
+
const FAN5 = [-0.95, -0.48, 0, 0.48, 0.95].map((a) => [Math.cos(a), Math.sin(a)]);
|
|
457
|
+
|
|
458
|
+
/** A loose seed: a short body hanging from a parachute of fine rays. */
|
|
459
|
+
function seed(ctx: CanvasRenderingContext2D, x: number, y: number, ang: number, size: number, fan: number[][]) {
|
|
460
|
+
const ux = Math.cos(ang), uy = Math.sin(ang);
|
|
461
|
+
ctx.moveTo(x, y);
|
|
462
|
+
ctx.lineTo(x - ux * size * 1.25, y - uy * size * 1.25);
|
|
463
|
+
for (const [c, s] of fan) {
|
|
464
|
+
ctx.moveTo(x, y);
|
|
465
|
+
ctx.lineTo(x + (ux * c - uy * s) * size, y + (ux * s + uy * c) * size);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
const dandelion: IconDraw = (ctx, r, time, k, t) => {
|
|
470
|
+
halo(ctx, r, t, k, 0.2);
|
|
471
|
+
const n = r < 18 ? 16 : r < 42 ? 34 : 60;
|
|
472
|
+
const pts = sphere(n);
|
|
473
|
+
const fan = r < 18 ? null : r < 42 ? FAN3 : FAN5;
|
|
474
|
+
const R = r * 0.56;
|
|
475
|
+
const cy = -r * 0.2;
|
|
476
|
+
const spin = time * 0.32, cs = Math.cos(spin), ss = Math.sin(spin);
|
|
477
|
+
const tilt = 0.42, ct = Math.cos(tilt), st = Math.sin(tilt);
|
|
478
|
+
const lw = thin(r);
|
|
479
|
+
const baseX = r * 0.06, baseY = r * 0.98;
|
|
480
|
+
ctx.save();
|
|
481
|
+
ctx.translate(baseX, baseY);
|
|
482
|
+
ctx.rotate(0.05 * Math.sin(time * 0.6));
|
|
483
|
+
ctx.translate(-baseX, -baseY);
|
|
484
|
+
// the stem
|
|
485
|
+
ctx.lineWidth = lw * 1.25;
|
|
486
|
+
ctx.strokeStyle = grad(t, 1, 0.5 + 0.15 * k);
|
|
487
|
+
ctx.beginPath();
|
|
488
|
+
ctx.moveTo(0, cy + R * 0.1);
|
|
489
|
+
ctx.quadraticCurveTo(r * 0.12, r * 0.45, baseX, baseY);
|
|
490
|
+
ctx.stroke();
|
|
491
|
+
// a faint puff behind the stalks, so even a tiny head reads as a ball
|
|
492
|
+
ctx.fillStyle = grad(t, 0.6, r < 18 ? 0.16 : 0.06 + 0.03 * k);
|
|
493
|
+
ctx.beginPath(); ctx.arc(0, cy, R * 0.92, 0, TAU); ctx.fill();
|
|
494
|
+
// the seed head: stalks + parachute tips, banded by depth (back = faint)
|
|
495
|
+
ctx.lineWidth = lw * 0.85;
|
|
496
|
+
for (let b = 0; b < 4; b++) {
|
|
497
|
+
const f = (b + 0.5) / 4;
|
|
498
|
+
ctx.strokeStyle = grad(t, 1 - f, (0.14 + 0.74 * f * f) * (0.85 + 0.15 * k));
|
|
499
|
+
ctx.beginPath();
|
|
500
|
+
for (let i = 0; i < n; i++) {
|
|
501
|
+
const x0 = pts[3 * i], y0 = pts[3 * i + 1], z0 = pts[3 * i + 2];
|
|
502
|
+
const x1 = x0 * cs + z0 * ss, z1 = -x0 * ss + z0 * cs;
|
|
503
|
+
const y2 = y0 * ct - z1 * st, z2 = y0 * st + z1 * ct;
|
|
504
|
+
if (bucket((z2 + 1) * 0.5) !== b) continue;
|
|
505
|
+
const sx = x1 * R, sy = -y2 * R;
|
|
506
|
+
ctx.moveTo(sx * 0.14, cy + sy * 0.14);
|
|
507
|
+
const ex = sx * 0.84, ey = cy + sy * 0.84;
|
|
508
|
+
ctx.lineTo(ex, ey);
|
|
509
|
+
if (fan) {
|
|
510
|
+
const l2 = Math.sqrt(x1 * x1 + y2 * y2);
|
|
511
|
+
const ux = l2 > 1e-3 ? x1 / l2 : 1, uy = l2 > 1e-3 ? -y2 / l2 : 0;
|
|
512
|
+
const len = r * 0.12 * (0.45 + 0.55 * l2);
|
|
513
|
+
for (const [c, s] of fan) {
|
|
514
|
+
ctx.moveTo(ex, ey);
|
|
515
|
+
ctx.lineTo(ex + (ux * c - uy * s) * len, ey + (ux * s + uy * c) * len);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
ctx.stroke();
|
|
520
|
+
}
|
|
521
|
+
ctx.fillStyle = grad(t, 0, 0.85);
|
|
522
|
+
ctx.beginPath(); ctx.arc(0, cy, Math.max(1, r * 0.065), 0, TAU); ctx.fill();
|
|
523
|
+
ctx.restore();
|
|
524
|
+
// one or two seeds drifting off on the wind
|
|
525
|
+
const loose = r < 18 ? 1 : 2;
|
|
526
|
+
ctx.save();
|
|
527
|
+
ctx.lineCap = 'round';
|
|
528
|
+
ctx.lineWidth = lw * 0.85;
|
|
529
|
+
for (let q = 0; q < loose; q++) {
|
|
530
|
+
const u = frac(time / 6.5 + q * 0.5 + 0.13);
|
|
531
|
+
const alpha = smoothstep(0, 0.12, u) * (1 - smoothstep(0.62, 1, u));
|
|
532
|
+
if (alpha < 0.02) continue;
|
|
533
|
+
const dir = q === 0 ? -0.5 : -1.15, away = q === 0 ? -0.15 : -0.45;
|
|
534
|
+
const sx = Math.cos(dir) * R * 0.96, sy = cy + Math.sin(dir) * R * 0.96;
|
|
535
|
+
const d = r * 0.46 * u;
|
|
536
|
+
const wob = Math.sin(u * 5 + q * 2) * r * 0.04;
|
|
537
|
+
const x = sx + Math.cos(away) * d - Math.sin(away) * wob;
|
|
538
|
+
const y = sy + Math.sin(away) * d + Math.cos(away) * wob;
|
|
539
|
+
ctx.strokeStyle = grad(t, 0.15, alpha * (0.75 + 0.2 * k));
|
|
540
|
+
ctx.beginPath();
|
|
541
|
+
seed(ctx, x, y, -Math.PI / 2 + 0.35 * Math.sin(time * 1.7 + q * 2.1), r * 0.1, fan ?? FAN3);
|
|
542
|
+
ctx.stroke();
|
|
543
|
+
}
|
|
544
|
+
ctx.restore();
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
/* ------------------------------------------------------------------- wave */
|
|
548
|
+
|
|
549
|
+
// The curl is a log spiral around (WX, WY), shrinking from the back of the wave into the eye.
|
|
550
|
+
const WX = 0.16, WY = -0.02, WA = -Math.PI, WB = 0.8 * Math.PI, WR = 0.95, WG = 0.2, WW = 0.42;
|
|
551
|
+
const waveRho = (a: number) => WR * Math.exp(-WG * (a - WA));
|
|
552
|
+
const waveInner = (a: number) => waveRho(a) - WW * Math.pow(Math.max(0, 1 - (a - WA) / (WB - WA)), 1.3);
|
|
553
|
+
const waterY = (x: number, ripple: number) => 0.45 - 0.03 * x + 0.025 * Math.sin(x * 9 + ripple);
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* The wave in r units: back, crest, lip curling into the eye and out again, the face, the rippled
|
|
557
|
+
* water line. With `close` it also runs along the sea floor, so it can be filled and clipped.
|
|
558
|
+
*/
|
|
559
|
+
function waveOutline(ctx: CanvasRenderingContext2D, r: number, seg: number, ripple: number, close: boolean) {
|
|
560
|
+
ctx.moveTo(-0.82 * r, 0.6 * r);
|
|
561
|
+
ctx.bezierCurveTo(-0.88 * r, 0.38 * r, -0.84 * r, 0.17 * r, (WX - WR) * r, WY * r);
|
|
562
|
+
for (let j = 1; j <= seg; j++) {
|
|
563
|
+
const a = WA + (j / seg) * (WB - WA);
|
|
564
|
+
const p = waveRho(a);
|
|
565
|
+
ctx.lineTo((WX + Math.cos(a) * p) * r, (WY + Math.sin(a) * p) * r);
|
|
566
|
+
}
|
|
567
|
+
for (let j = seg; j >= 0; j--) {
|
|
568
|
+
const a = WA + (j / seg) * (WB - WA);
|
|
569
|
+
const p = waveInner(a);
|
|
570
|
+
ctx.lineTo((WX + Math.cos(a) * p) * r, (WY + Math.sin(a) * p) * r);
|
|
571
|
+
}
|
|
572
|
+
const x0 = -0.36, x1 = 0.84;
|
|
573
|
+
ctx.bezierCurveTo(-0.42 * r, 0.14 * r, -0.44 * r, 0.34 * r, x0 * r, waterY(x0, ripple) * r);
|
|
574
|
+
const n = Math.max(6, Math.round(seg * 0.5));
|
|
575
|
+
for (let j = 1; j <= n; j++) {
|
|
576
|
+
const x = x0 + (j / n) * (x1 - x0);
|
|
577
|
+
ctx.lineTo(x * r, waterY(x, ripple) * r);
|
|
578
|
+
}
|
|
579
|
+
if (close) {
|
|
580
|
+
ctx.quadraticCurveTo(0.9 * r, 0.58 * r, 0.7 * r, 0.64 * r);
|
|
581
|
+
ctx.lineTo(-0.7 * r, 0.66 * r);
|
|
582
|
+
ctx.closePath();
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
const wave: IconDraw = (ctx, r, time, k, t) => {
|
|
587
|
+
halo(ctx, r, t, k, 0.22);
|
|
588
|
+
const seg = r < 18 ? 18 : r < 42 ? 28 : 40;
|
|
589
|
+
const ds = r < 18 ? 0.2 : r < 42 ? 0.13 : 0.09;
|
|
590
|
+
const scroll = frac(time * 0.32);
|
|
591
|
+
const ripple = -time * 2.2;
|
|
592
|
+
ctx.save();
|
|
593
|
+
ctx.translate(0, Math.sin(time * 0.9) * r * 0.025);
|
|
594
|
+
ctx.rotate(0.04 * Math.sin(time * 0.6));
|
|
595
|
+
ctx.lineJoin = 'round';
|
|
596
|
+
ctx.beginPath();
|
|
597
|
+
waveOutline(ctx, r, seg, ripple, true);
|
|
598
|
+
ctx.fillStyle = grad(t, 1, 0.08);
|
|
599
|
+
ctx.fill();
|
|
600
|
+
ctx.save();
|
|
601
|
+
ctx.clip();
|
|
602
|
+
// flow stripes: bands that follow the curl and scroll outward from the eye
|
|
603
|
+
const a0 = WA - 0.85 * Math.PI;
|
|
604
|
+
const sMin = 0.3, sMax = 1.25;
|
|
605
|
+
const count = Math.ceil((sMax - sMin) / ds);
|
|
606
|
+
const steps = seg + 8;
|
|
607
|
+
for (let b = 0; b < 4; b++) {
|
|
608
|
+
const f = (b + 0.5) / 4;
|
|
609
|
+
ctx.fillStyle = grad(t, 1 - f, (0.2 + 0.68 * f) * (0.86 + 0.14 * k));
|
|
610
|
+
ctx.beginPath();
|
|
611
|
+
for (let i = 0; i < count; i++) {
|
|
612
|
+
const s = sMin + (i + scroll) * ds;
|
|
613
|
+
const v = 0.25 + 0.75 * smoothstep(sMin, 1.05, s) * (0.55 + 0.45 * Math.sin(i * 1.9 + 0.5));
|
|
614
|
+
if (bucket(v) !== b) continue;
|
|
615
|
+
const s2 = s - ds * 0.5;
|
|
616
|
+
for (let j = 0; j <= steps; j++) {
|
|
617
|
+
const a = a0 + (j / steps) * (WB - a0);
|
|
618
|
+
const p = waveRho(a) * s;
|
|
619
|
+
j ? ctx.lineTo((WX + Math.cos(a) * p) * r, (WY + Math.sin(a) * p) * r) : ctx.moveTo((WX + Math.cos(a) * p) * r, (WY + Math.sin(a) * p) * r);
|
|
620
|
+
}
|
|
621
|
+
for (let j = steps; j >= 0; j--) {
|
|
622
|
+
const a = a0 + (j / steps) * (WB - a0);
|
|
623
|
+
const p = waveRho(a) * s2;
|
|
624
|
+
ctx.lineTo((WX + Math.cos(a) * p) * r, (WY + Math.sin(a) * p) * r);
|
|
625
|
+
}
|
|
626
|
+
ctx.closePath();
|
|
627
|
+
}
|
|
628
|
+
ctx.fill();
|
|
629
|
+
}
|
|
630
|
+
ctx.restore();
|
|
631
|
+
// the outline along the top (the sea floor stays open)
|
|
632
|
+
ctx.lineWidth = thin(r);
|
|
633
|
+
ctx.strokeStyle = grad(t, 0, 0.62 + 0.28 * k);
|
|
634
|
+
ctx.beginPath();
|
|
635
|
+
waveOutline(ctx, r, seg, ripple, false);
|
|
636
|
+
ctx.stroke();
|
|
637
|
+
// foam: spray leaving the crest, plus a few flecks riding the water line
|
|
638
|
+
const spray = r < 18 ? 2 : r < 42 ? 4 : 7;
|
|
639
|
+
const flecks = r < 18 ? 0 : r < 42 ? 2 : 3;
|
|
640
|
+
for (let g = 0; g < 2; g++) {
|
|
641
|
+
ctx.fillStyle = grad(t, 0, g ? 0.95 : 0.5);
|
|
642
|
+
ctx.beginPath();
|
|
643
|
+
for (let i = 0; i < spray; i++) {
|
|
644
|
+
const u = frac(time * (0.32 + 0.1 * hashA(i + 0.7)) + hashB(i * 2.3));
|
|
645
|
+
if ((u < 0.5 ? 1 : 0) !== g) continue;
|
|
646
|
+
const a = -0.75 * Math.PI + (i / Math.max(1, spray - 1)) * 0.7 * Math.PI;
|
|
647
|
+
const p = waveRho(a) + 0.04 + 0.16 * u;
|
|
648
|
+
const x = (WX + Math.cos(a) * p) * r, y = (WY + Math.sin(a) * p - 0.05 * u) * r;
|
|
649
|
+
const rad = Math.max(0.55, r * 0.03 * (1 - 0.55 * u));
|
|
650
|
+
ctx.moveTo(x + rad, y); ctx.arc(x, y, rad, 0, TAU);
|
|
651
|
+
}
|
|
652
|
+
for (let i = 0; i < flecks; i++) {
|
|
653
|
+
if (g !== (i % 2)) continue;
|
|
654
|
+
const x = frac(0.3 * i + time * 0.06) * 1.1 - 0.3;
|
|
655
|
+
const y = waterY(x, ripple) - 0.05;
|
|
656
|
+
const rad = Math.max(0.55, r * 0.022);
|
|
657
|
+
ctx.moveTo(x * r + rad, y * r); ctx.arc(x * r, y * r, rad, 0, TAU);
|
|
658
|
+
}
|
|
659
|
+
ctx.fill();
|
|
660
|
+
}
|
|
661
|
+
ctx.restore();
|
|
662
|
+
};
|
|
663
|
+
|
|
664
|
+
/* -------------------------------------------------------------- honeycomb */
|
|
665
|
+
|
|
666
|
+
const HEX: number[][] = [];
|
|
667
|
+
for (let i = 0; i < 6; i++) HEX.push([Math.cos(Math.PI / 6 + (i * Math.PI) / 3), Math.sin(Math.PI / 6 + (i * Math.PI) / 3)]);
|
|
668
|
+
/** Cells of a round comb patch, in cell units (centre distance from the middle in `d`). */
|
|
669
|
+
const COMB: Record<string, { x: number; y: number; d: number; id: number }[]> = {};
|
|
670
|
+
function comb(reach: number) {
|
|
671
|
+
const key = reach.toFixed(2);
|
|
672
|
+
let cells = COMB[key];
|
|
673
|
+
if (cells) return cells;
|
|
674
|
+
cells = [];
|
|
675
|
+
const m = Math.ceil(reach) + 2;
|
|
676
|
+
for (let q = -m; q <= m; q++) {
|
|
677
|
+
for (let s = -m; s <= m; s++) {
|
|
678
|
+
const x = Math.sqrt(3) * (q + s / 2), y = 1.5 * s;
|
|
679
|
+
const d = Math.sqrt(x * x + y * y);
|
|
680
|
+
if (d <= reach) cells.push({ x, y, d, id: q * 31 + s * 7 });
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
return (COMB[key] = cells);
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
const honeycomb: IconDraw = (ctx, r, time, k, t) => {
|
|
687
|
+
halo(ctx, r, t, k, 0.22);
|
|
688
|
+
const h = r * (r < 18 ? 0.29 : r < 42 ? 0.2 : 0.15);
|
|
689
|
+
const cells = comb((r * 0.8) / h);
|
|
690
|
+
const reach = (r * 0.8) / h;
|
|
691
|
+
const dx = Math.cos(0.6), dy = Math.sin(0.6);
|
|
692
|
+
ctx.save();
|
|
693
|
+
ctx.rotate(0.1 * Math.sin(time * 0.25));
|
|
694
|
+
ctx.lineJoin = 'round';
|
|
695
|
+
// honey: a light travelling across the filled cells
|
|
696
|
+
const inner = h * 0.74;
|
|
697
|
+
for (let b = 0; b < 4; b++) {
|
|
698
|
+
const f = (b + 0.5) / 4;
|
|
699
|
+
ctx.fillStyle = grad(t, 1 - f, 0.12 + 0.78 * f * (0.85 + 0.15 * k));
|
|
700
|
+
ctx.beginPath();
|
|
701
|
+
for (const c of cells) {
|
|
702
|
+
if (hashB(c.id * 0.37 + 1.3) < 0.24) continue; // some cells stay empty
|
|
703
|
+
const x = c.x * h, y = c.y * h;
|
|
704
|
+
const w = 0.5 + 0.5 * Math.sin(((x * dx + y * dy) / r) * 2.6 - time * 1.5);
|
|
705
|
+
const edge = 1 - smoothstep(reach - 1.3, reach + 0.2, c.d);
|
|
706
|
+
if (bucket((0.15 + 0.85 * w * w * w) * edge) !== b) continue;
|
|
707
|
+
ctx.moveTo(x + HEX[0][0] * inner, y + HEX[0][1] * inner);
|
|
708
|
+
for (let i = 1; i < 6; i++) ctx.lineTo(x + HEX[i][0] * inner, y + HEX[i][1] * inner);
|
|
709
|
+
ctx.closePath();
|
|
710
|
+
}
|
|
711
|
+
ctx.fill();
|
|
712
|
+
}
|
|
713
|
+
// the walls
|
|
714
|
+
ctx.lineWidth = thin(r);
|
|
715
|
+
for (let g = 0; g < 2; g++) {
|
|
716
|
+
ctx.strokeStyle = grad(t, g ? 0.1 : 0.6, (g ? 0.62 : 0.3) + 0.2 * k);
|
|
717
|
+
ctx.beginPath();
|
|
718
|
+
for (const c of cells) {
|
|
719
|
+
const outer = c.d > reach - 1.2 ? 0 : 1;
|
|
720
|
+
if (outer !== g) continue;
|
|
721
|
+
const x = c.x * h, y = c.y * h;
|
|
722
|
+
ctx.moveTo(x + HEX[0][0] * h, y + HEX[0][1] * h);
|
|
723
|
+
for (let i = 1; i < 6; i++) ctx.lineTo(x + HEX[i][0] * h, y + HEX[i][1] * h);
|
|
724
|
+
ctx.closePath();
|
|
725
|
+
}
|
|
726
|
+
ctx.stroke();
|
|
727
|
+
}
|
|
728
|
+
// a glint in the brightest cells
|
|
729
|
+
if (r >= 42) {
|
|
730
|
+
ctx.fillStyle = grad(t, 0, 0.9);
|
|
731
|
+
ctx.beginPath();
|
|
732
|
+
for (const c of cells) {
|
|
733
|
+
if (hashB(c.id * 0.37 + 1.3) < 0.24) continue;
|
|
734
|
+
const x = c.x * h, y = c.y * h;
|
|
735
|
+
const w = 0.5 + 0.5 * Math.sin(((x * dx + y * dy) / r) * 2.6 - time * 1.5);
|
|
736
|
+
if (w < 0.82 || c.d > reach - 1) continue;
|
|
737
|
+
const gx = x - h * 0.28, gy = y - h * 0.26, gr = Math.max(0.6, h * 0.09);
|
|
738
|
+
ctx.moveTo(gx + gr, gy); ctx.arc(gx, gy, gr, 0, TAU);
|
|
739
|
+
}
|
|
740
|
+
ctx.fill();
|
|
741
|
+
}
|
|
742
|
+
ctx.restore();
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
/* ----------------------------------------------------------------- clover */
|
|
746
|
+
|
|
747
|
+
/* A heart-shaped leaf in unit length: point at the stem (0, 0), lobes out at x = 1, notch at 0.78. */
|
|
748
|
+
const HEART = [0, 0, 0.16, -0.24, 0.46, -0.62, 0.8, -0.5, 1.1, -0.38, 1.02, -0.05, 0.78, 0, 1.02, 0.05, 1.1, 0.38, 0.8, 0.5, 0.46, 0.62, 0.16, 0.24, 0, 0];
|
|
749
|
+
const HP = new Float64Array(HEART.length);
|
|
750
|
+
|
|
751
|
+
/** One leaf along the current turn, length `L`; `sc` shrinks it around its middle (the inner contour). */
|
|
752
|
+
function heart(ctx: CanvasRenderingContext2D, L: number, sc = 1) {
|
|
753
|
+
for (let i = 0; i < HEART.length; i += 2) {
|
|
754
|
+
const x = (0.5 + (HEART[i] - 0.5) * sc) * L, y = HEART[i + 1] * sc * L;
|
|
755
|
+
HP[i] = X(x, y); HP[i + 1] = Y(x, y);
|
|
756
|
+
}
|
|
757
|
+
ctx.moveTo(HP[0], HP[1]);
|
|
758
|
+
for (let i = 2; i < HP.length; i += 6) ctx.bezierCurveTo(HP[i], HP[i + 1], HP[i + 2], HP[i + 3], HP[i + 4], HP[i + 5]);
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
const clover: IconDraw = (ctx, r, time, k, t) => {
|
|
762
|
+
halo(ctx, r, t, k, 0.22);
|
|
763
|
+
const four = r >= 42;
|
|
764
|
+
const n = four ? 4 : 3;
|
|
765
|
+
const L = r * (four ? 0.53 : 0.56);
|
|
766
|
+
const cy = -r * 0.16;
|
|
767
|
+
const baseX = r * 0.16, baseY = r * 0.94;
|
|
768
|
+
const lw = thin(r);
|
|
769
|
+
ctx.save();
|
|
770
|
+
ctx.lineJoin = 'round';
|
|
771
|
+
ctx.lineCap = 'round';
|
|
772
|
+
// the whole plant sways from the foot of its stem
|
|
773
|
+
ctx.translate(baseX, baseY);
|
|
774
|
+
ctx.rotate(0.07 * Math.sin(time * 0.7));
|
|
775
|
+
ctx.translate(-baseX, -baseY);
|
|
776
|
+
ctx.lineWidth = lw * 1.3;
|
|
777
|
+
ctx.strokeStyle = grad(t, 1, 0.55 + 0.15 * k);
|
|
778
|
+
ctx.beginPath();
|
|
779
|
+
ctx.moveTo(0, cy);
|
|
780
|
+
ctx.quadraticCurveTo(r * 0.02, r * 0.5, baseX, baseY);
|
|
781
|
+
ctx.stroke();
|
|
782
|
+
ctx.translate(0, cy);
|
|
783
|
+
ctx.lineWidth = lw;
|
|
784
|
+
for (let i = 0; i < n; i++) {
|
|
785
|
+
const a = four ? -0.75 * Math.PI + i * (Math.PI / 2) : -Math.PI / 2 + i * (TAU / 3);
|
|
786
|
+
const breathe = Math.sin(time * 1.1 + i * 1.7);
|
|
787
|
+
const len = L * (0.96 + 0.05 * breathe) * (0.97 + 0.04 * k);
|
|
788
|
+
const f = i / (n - 1);
|
|
789
|
+
turnTo(a + 0.05 * Math.sin(time * 0.9 + i * 2.2));
|
|
790
|
+
ctx.strokeStyle = grad(t, f * 0.7, (0.72 + 0.16 * breathe) * (0.86 + 0.14 * k));
|
|
791
|
+
ctx.beginPath();
|
|
792
|
+
heart(ctx, len);
|
|
793
|
+
ctx.stroke();
|
|
794
|
+
if (r >= 18) {
|
|
795
|
+
// the mid vein, and on big tiles a second, inner contour
|
|
796
|
+
ctx.strokeStyle = grad(t, 0.3 + f * 0.6, (0.34 + 0.1 * breathe) * (0.86 + 0.14 * k));
|
|
797
|
+
ctx.beginPath();
|
|
798
|
+
ctx.moveTo(X(0.1 * len, 0), Y(0.1 * len, 0));
|
|
799
|
+
ctx.lineTo(X(0.7 * len, 0), Y(0.7 * len, 0));
|
|
800
|
+
if (four) heart(ctx, len, 0.62);
|
|
801
|
+
ctx.stroke();
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
ctx.fillStyle = grad(t, 0, 0.85);
|
|
805
|
+
ctx.beginPath(); ctx.arc(0, 0, Math.max(0.8, r * 0.035), 0, TAU); ctx.fill();
|
|
806
|
+
ctx.restore();
|
|
807
|
+
};
|
|
808
|
+
|
|
809
|
+
export const iconsA: Record<'daisy' | 'tree_rings' | 'fireflies' | 'nautilus' | 'dandelion' | 'wave' | 'honeycomb' | 'clover', IconDraw> = {
|
|
810
|
+
daisy,
|
|
811
|
+
tree_rings: treeRings,
|
|
812
|
+
fireflies,
|
|
813
|
+
nautilus,
|
|
814
|
+
dandelion,
|
|
815
|
+
wave,
|
|
816
|
+
honeycomb,
|
|
817
|
+
clover,
|
|
818
|
+
};
|