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,827 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Bloom Wall icons, set B: sun, rain, crystal, moon, pinecone, ripples, mushroom, leaf.
|
|
3
|
+
*
|
|
4
|
+
* Every icon is drawn around (0, 0) inside radius r, halo first. Strokes are
|
|
5
|
+
* grouped into 4 brightness bands (`bucket`) so a whole icon costs a handful of
|
|
6
|
+
* fills and strokes. All colour comes from the tint `t`, so a sleeping tile
|
|
7
|
+
* fades to grey line art by itself. Detail steps down below r 42 and r 18.
|
|
8
|
+
*/
|
|
9
|
+
import { TAU, bucket, clamp, clamp01, grad, halo, hashA, hashB, rampColor } from '../paint';
|
|
10
|
+
import type { IconDraw } from './types';
|
|
11
|
+
|
|
12
|
+
type Ctx = CanvasRenderingContext2D;
|
|
13
|
+
|
|
14
|
+
const frac = (v: number) => v - Math.floor(v);
|
|
15
|
+
const hair = (r: number) => clamp(r * 0.022, 0.65, 1.5);
|
|
16
|
+
|
|
17
|
+
/** Night-forest shade and soft white, as cached rgba() strings (neutral, so they suit a grey tile too). */
|
|
18
|
+
const SHADE: string[] = [];
|
|
19
|
+
const LIGHT: string[] = [];
|
|
20
|
+
for (let i = 0; i <= 32; i++) {
|
|
21
|
+
SHADE.push(`rgba(6,12,9,${(i / 32).toFixed(4)})`);
|
|
22
|
+
LIGHT.push(`rgba(255,255,255,${(i / 32).toFixed(4)})`);
|
|
23
|
+
}
|
|
24
|
+
const shade = (a: number) => SHADE[Math.round(clamp01(a) * 32)];
|
|
25
|
+
const light = (a: number) => LIGHT[Math.round(clamp01(a) * 32)];
|
|
26
|
+
|
|
27
|
+
/* ------------------------------------------------------------------ sun */
|
|
28
|
+
|
|
29
|
+
const sun: IconDraw = (ctx, r, time, k, t) => {
|
|
30
|
+
halo(ctx, r, t, k, 0.22);
|
|
31
|
+
const lw = hair(r);
|
|
32
|
+
const n = r < 18 ? 6 : r < 42 ? 10 : 14;
|
|
33
|
+
const beat = 0.5 + 0.5 * Math.sin(time * 1.2);
|
|
34
|
+
const disc = r * (0.36 + 0.02 * k + 0.014 * beat);
|
|
35
|
+
ctx.save();
|
|
36
|
+
ctx.rotate(time * 0.12);
|
|
37
|
+
ctx.lineWidth = lw;
|
|
38
|
+
ctx.lineJoin = 'round';
|
|
39
|
+
const total = n * 2;
|
|
40
|
+
for (let b = 0; b < 4; b++) {
|
|
41
|
+
const f = (b + 0.5) / 4;
|
|
42
|
+
ctx.strokeStyle = grad(t, 1 - f, 0.3 + 0.64 * f);
|
|
43
|
+
ctx.beginPath();
|
|
44
|
+
for (let i = 0; i < total; i++) {
|
|
45
|
+
const a = (i / total) * TAU;
|
|
46
|
+
const w = 0.5 + 0.5 * Math.sin(a * 2 - time * 1.7);
|
|
47
|
+
if (bucket(w) !== b) continue;
|
|
48
|
+
const ca = Math.cos(a), sa = Math.sin(a);
|
|
49
|
+
if ((i & 1) === 0) {
|
|
50
|
+
// long ray: a slim lancet
|
|
51
|
+
const r0 = disc + r * 0.1;
|
|
52
|
+
const tip = r * (0.84 + 0.1 * w * (0.75 + 0.3 * k)) * (0.97 + 0.04 * beat);
|
|
53
|
+
if (r < 18) {
|
|
54
|
+
ctx.moveTo(ca * r0, sa * r0); ctx.lineTo(ca * tip, sa * tip);
|
|
55
|
+
} else {
|
|
56
|
+
const hw = r * 0.05;
|
|
57
|
+
ctx.moveTo(ca * r0 - sa * hw, sa * r0 + ca * hw);
|
|
58
|
+
ctx.lineTo(ca * tip, sa * tip);
|
|
59
|
+
ctx.lineTo(ca * r0 + sa * hw, sa * r0 - ca * hw);
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
// short ray: a plain line
|
|
63
|
+
const r0 = disc + r * 0.13;
|
|
64
|
+
const tip = r * (0.6 + 0.07 * w) * (0.97 + 0.04 * beat);
|
|
65
|
+
ctx.moveTo(ca * r0, sa * r0); ctx.lineTo(ca * tip, sa * tip);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
ctx.stroke();
|
|
69
|
+
}
|
|
70
|
+
// the disc
|
|
71
|
+
ctx.beginPath(); ctx.arc(0, 0, disc, 0, TAU);
|
|
72
|
+
ctx.fillStyle = grad(t, 0, 0.07 + 0.06 * k);
|
|
73
|
+
ctx.fill();
|
|
74
|
+
ctx.strokeStyle = grad(t, 0, 0.8 + 0.18 * k);
|
|
75
|
+
ctx.lineWidth = clamp(r * 0.03, 0.85, 1.9);
|
|
76
|
+
ctx.stroke();
|
|
77
|
+
if (r >= 18) {
|
|
78
|
+
// a dashed inner ring turning the other way
|
|
79
|
+
const segs = r < 42 ? 8 : 12, ir = disc * 0.7, span = TAU / segs;
|
|
80
|
+
ctx.rotate(-time * 0.34);
|
|
81
|
+
ctx.lineWidth = lw;
|
|
82
|
+
ctx.strokeStyle = grad(t, 0.45, 0.42 + 0.3 * k);
|
|
83
|
+
ctx.beginPath();
|
|
84
|
+
for (let i = 0; i < segs; i++) {
|
|
85
|
+
const a0 = i * span;
|
|
86
|
+
ctx.moveTo(Math.cos(a0) * ir, Math.sin(a0) * ir);
|
|
87
|
+
ctx.arc(0, 0, ir, a0, a0 + span * 0.55);
|
|
88
|
+
}
|
|
89
|
+
ctx.stroke();
|
|
90
|
+
}
|
|
91
|
+
ctx.fillStyle = grad(t, 0, 0.9);
|
|
92
|
+
ctx.beginPath(); ctx.arc(0, 0, clamp(r * 0.05, 1, 3), 0, TAU); ctx.fill();
|
|
93
|
+
ctx.restore();
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/* ----------------------------------------------------------------- rain */
|
|
97
|
+
|
|
98
|
+
/** A teardrop with its round end at (x, y), tail leaning with the wind. */
|
|
99
|
+
function drop(ctx: Ctx, x: number, y: number, d: number, lean: number) {
|
|
100
|
+
const ty = y - d * 2.7, tx = x - lean * d * 2.7;
|
|
101
|
+
ctx.moveTo(tx, ty);
|
|
102
|
+
ctx.quadraticCurveTo(x + d * 0.95, y - d, x + d, y);
|
|
103
|
+
ctx.arc(x, y, d, 0, Math.PI);
|
|
104
|
+
ctx.quadraticCurveTo(x - d * 0.95, y - d, tx, ty);
|
|
105
|
+
ctx.closePath();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const rain: IconDraw = (ctx, r, time, k, t) => {
|
|
109
|
+
halo(ctx, r, t, k, 0.22);
|
|
110
|
+
const R = r * (0.9 + 0.03 * k);
|
|
111
|
+
const cols = r < 18 ? 5 : r < 42 ? 7 : 9;
|
|
112
|
+
const pitch = (R * 2) / cols;
|
|
113
|
+
const rowPitch = pitch * 1.3;
|
|
114
|
+
const rows = Math.ceil((R * 2) / rowPitch) + 2;
|
|
115
|
+
const surface = R * 0.56;
|
|
116
|
+
const wind = 0.2;
|
|
117
|
+
const fall = time * 1.05;
|
|
118
|
+
const size = pitch * (r < 18 ? 0.28 : 0.24) * (0.88 + 0.18 * k);
|
|
119
|
+
const top = -R - rowPitch;
|
|
120
|
+
const half = Math.sqrt(R * R - surface * surface);
|
|
121
|
+
const th0 = Math.asin(surface / R);
|
|
122
|
+
|
|
123
|
+
// the pool under the water line
|
|
124
|
+
ctx.fillStyle = grad(t, 1, 0.1 + 0.05 * k);
|
|
125
|
+
ctx.beginPath(); ctx.moveTo(half, surface); ctx.arc(0, 0, R, th0, Math.PI - th0); ctx.closePath(); ctx.fill();
|
|
126
|
+
|
|
127
|
+
// drops, brightest in the middle of the window like a halftone
|
|
128
|
+
for (let b = 0; b < 4; b++) {
|
|
129
|
+
const f = (b + 0.5) / 4;
|
|
130
|
+
ctx.fillStyle = grad(t, 1 - f, 0.34 + 0.62 * f);
|
|
131
|
+
ctx.beginPath();
|
|
132
|
+
for (let j = -1; j <= cols; j++) {
|
|
133
|
+
const xj = -R + (j + 0.5) * pitch;
|
|
134
|
+
const shift = frac(fall + hashA(j + 3.7));
|
|
135
|
+
for (let i = 0; i < rows; i++) {
|
|
136
|
+
const y = top + (i + shift) * rowPitch;
|
|
137
|
+
if (y > surface - size) continue;
|
|
138
|
+
const x = xj + y * wind;
|
|
139
|
+
const d2 = (x * x + y * y) / (R * R);
|
|
140
|
+
if (d2 > 0.9) continue;
|
|
141
|
+
const sh = 1 - d2;
|
|
142
|
+
if (bucket(sh) !== b) continue;
|
|
143
|
+
const d = Math.max(0.5, size * (0.22 + 0.78 * sh));
|
|
144
|
+
if (r < 18 || d < 1) { ctx.moveTo(x + d, y); ctx.arc(x, y, d, 0, TAU); }
|
|
145
|
+
else drop(ctx, x, y, d, wind);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
ctx.fill();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// splash rings where each column lands
|
|
152
|
+
const lw = hair(r);
|
|
153
|
+
ctx.lineWidth = lw * 0.9;
|
|
154
|
+
for (let b = 0; b < 4; b++) {
|
|
155
|
+
const f = (b + 0.5) / 4;
|
|
156
|
+
ctx.strokeStyle = grad(t, 1 - f, 0.3 + 0.62 * f);
|
|
157
|
+
ctx.beginPath();
|
|
158
|
+
for (let j = -1; j <= cols; j++) {
|
|
159
|
+
const xs = -R + (j + 0.5) * pitch + surface * wind;
|
|
160
|
+
if (Math.abs(xs) > half * 0.86) continue;
|
|
161
|
+
const p = frac((top + frac(fall + hashA(j + 3.7)) * rowPitch - surface) / rowPitch);
|
|
162
|
+
const fade = (1 - p) * (1 - p);
|
|
163
|
+
if (bucket(fade) !== b) continue;
|
|
164
|
+
const rad = pitch * (0.12 + 0.72 * p);
|
|
165
|
+
ctx.moveTo(xs + rad, surface); ctx.ellipse(xs, surface, rad, rad * 0.3, 0, 0, TAU);
|
|
166
|
+
}
|
|
167
|
+
ctx.stroke();
|
|
168
|
+
}
|
|
169
|
+
if (r >= 42) {
|
|
170
|
+
// two tiny droplets jump up from every fresh splash
|
|
171
|
+
ctx.fillStyle = grad(t, 0, 0.7);
|
|
172
|
+
ctx.beginPath();
|
|
173
|
+
for (let j = -1; j <= cols; j++) {
|
|
174
|
+
const xs = -R + (j + 0.5) * pitch + surface * wind;
|
|
175
|
+
if (Math.abs(xs) > half * 0.86) continue;
|
|
176
|
+
const p = frac((top + frac(fall + hashA(j + 3.7)) * rowPitch - surface) / rowPitch);
|
|
177
|
+
if (p > 0.4) continue;
|
|
178
|
+
const q = p / 0.4, lift = Math.sin(q * Math.PI) * pitch * 0.42, dd = Math.max(0.6, size * 0.32 * (1 - q));
|
|
179
|
+
const spread = pitch * 0.3 * q;
|
|
180
|
+
ctx.moveTo(xs - spread + dd, surface - lift); ctx.arc(xs - spread, surface - lift, dd, 0, TAU);
|
|
181
|
+
ctx.moveTo(xs + spread + dd, surface - lift * 0.8); ctx.arc(xs + spread, surface - lift * 0.8, dd, 0, TAU);
|
|
182
|
+
}
|
|
183
|
+
ctx.fill();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// window rim
|
|
187
|
+
ctx.strokeStyle = grad(t, 0, 0.42 + 0.24 * k);
|
|
188
|
+
ctx.lineWidth = clamp(r * 0.025, 0.75, 1.8);
|
|
189
|
+
ctx.beginPath(); ctx.arc(0, 0, R, 0, TAU); ctx.stroke();
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
/* -------------------------------------------------------------- crystal */
|
|
193
|
+
|
|
194
|
+
// ground x, ground z, lean direction, lean, half-width, body length, tip length (in r)
|
|
195
|
+
// a tall one in the middle, three leaning out a third of a turn apart, so it is wide from every side
|
|
196
|
+
const PRISMS: readonly (readonly number[])[] = [
|
|
197
|
+
[0.0, 0.0, 0.4, 0.05, 0.2, 0.86, 0.36],
|
|
198
|
+
[0.12, 0.0, 0.0, 0.66, 0.15, 0.62, 0.26],
|
|
199
|
+
[-0.071, 0.097, 2.2, 0.72, 0.13, 0.52, 0.22],
|
|
200
|
+
[-0.069, -0.098, 4.1, 0.58, 0.12, 0.46, 0.2],
|
|
201
|
+
];
|
|
202
|
+
const CRYS = new Float64Array(PRISMS.length * 13 * 3);
|
|
203
|
+
|
|
204
|
+
/** One crystal edge (corner indices a, b) if its depth falls in this band. */
|
|
205
|
+
function crystalEdge(ctx: Ctx, a: number, b: number, band: number) {
|
|
206
|
+
const z = (CRYS[a * 3 + 2] + CRYS[b * 3 + 2]) * 0.5;
|
|
207
|
+
if (bucket(0.5 + z * 1.3) !== band) return;
|
|
208
|
+
ctx.moveTo(CRYS[a * 3], CRYS[a * 3 + 1]);
|
|
209
|
+
ctx.lineTo(CRYS[b * 3], CRYS[b * 3 + 1]);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const crystal: IconDraw = (ctx, r, time, k, t) => {
|
|
213
|
+
halo(ctx, r, t, k, 0.24);
|
|
214
|
+
const lw = hair(r);
|
|
215
|
+
const spin = time * 0.3;
|
|
216
|
+
const cs = Math.cos(spin), ss = Math.sin(spin);
|
|
217
|
+
const cp = Math.cos(0.38), sp = Math.sin(0.38);
|
|
218
|
+
const ground = -0.6;
|
|
219
|
+
const count = r < 18 ? 3 : PRISMS.length;
|
|
220
|
+
const s = r * (1.3 + 0.03 * k);
|
|
221
|
+
|
|
222
|
+
// every corner of every prism: 6 at the foot, 6 at the shoulder, then the tip
|
|
223
|
+
for (let p = 0; p < count; p++) {
|
|
224
|
+
const P = PRISMS[p];
|
|
225
|
+
const bx = P[0], bz = P[1], cd = Math.cos(P[2]), sd = Math.sin(P[2]);
|
|
226
|
+
const cl = Math.cos(P[3]), sl = Math.sin(P[3]), w = P[4], body = P[5], tip = P[6];
|
|
227
|
+
for (let v = 0; v < 13; v++) {
|
|
228
|
+
let lx = 0, ly = body + tip, lz = 0;
|
|
229
|
+
if (v < 12) {
|
|
230
|
+
const a = (v % 6) * (TAU / 6) + p * 0.4;
|
|
231
|
+
lx = Math.cos(a) * w; lz = Math.sin(a) * w; ly = v < 6 ? 0 : body;
|
|
232
|
+
}
|
|
233
|
+
const x1 = lx * cl + ly * sl, y1 = -lx * sl + ly * cl;
|
|
234
|
+
const x2 = x1 * cd - lz * sd + bx, z2 = x1 * sd + lz * cd + bz, y2 = y1 + ground;
|
|
235
|
+
const x3 = x2 * cs - z2 * ss, z3 = x2 * ss + z2 * cs;
|
|
236
|
+
const o = (p * 13 + v) * 3;
|
|
237
|
+
CRYS[o] = x3 * s;
|
|
238
|
+
CRYS[o + 1] = -(y2 * cp - z3 * sp) * s;
|
|
239
|
+
CRYS[o + 2] = y2 * sp + z3 * cp;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
ctx.save();
|
|
244
|
+
ctx.lineJoin = 'round';
|
|
245
|
+
// the bed it grows from
|
|
246
|
+
ctx.strokeStyle = grad(t, 1, 0.22 + 0.1 * k);
|
|
247
|
+
ctx.lineWidth = lw;
|
|
248
|
+
ctx.beginPath(); ctx.ellipse(0, -ground * cp * s, 0.44 * s, 0.44 * sp * s, 0, 0, TAU); ctx.stroke();
|
|
249
|
+
|
|
250
|
+
// edges, back ones dim, front ones bright
|
|
251
|
+
for (let b = 0; b < 4; b++) {
|
|
252
|
+
const f = (b + 0.5) / 4;
|
|
253
|
+
ctx.strokeStyle = grad(t, 1 - f, 0.2 + 0.74 * f * (0.86 + 0.16 * k));
|
|
254
|
+
ctx.beginPath();
|
|
255
|
+
for (let p = 0; p < count; p++) {
|
|
256
|
+
const o = p * 13;
|
|
257
|
+
for (let j = 0; j < 6; j++) {
|
|
258
|
+
const j2 = (j + 1) % 6;
|
|
259
|
+
crystalEdge(ctx, o + j, o + 6 + j, b);
|
|
260
|
+
crystalEdge(ctx, o + 6 + j, o + 6 + j2, b);
|
|
261
|
+
crystalEdge(ctx, o + 6 + j, o + 12, b);
|
|
262
|
+
if (r >= 18) crystalEdge(ctx, o + j, o + j2, b);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
ctx.stroke();
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// growth lines across the faces that look at us
|
|
269
|
+
if (r >= 42) {
|
|
270
|
+
ctx.strokeStyle = grad(t, 0.5, 0.2 + 0.16 * k);
|
|
271
|
+
ctx.beginPath();
|
|
272
|
+
for (let p = 0; p < count; p++) {
|
|
273
|
+
const o = p * 13;
|
|
274
|
+
let zc = 0;
|
|
275
|
+
for (let v = 0; v < 12; v++) zc += CRYS[(o + v) * 3 + 2];
|
|
276
|
+
zc /= 12;
|
|
277
|
+
for (let j = 0; j < 6; j++) {
|
|
278
|
+
const a = o + j, b2 = o + (j + 1) % 6, c = o + 6 + j, d = o + 6 + (j + 1) % 6;
|
|
279
|
+
const zf = (CRYS[a * 3 + 2] + CRYS[b2 * 3 + 2] + CRYS[c * 3 + 2] + CRYS[d * 3 + 2]) * 0.25;
|
|
280
|
+
if (zf - zc < PRISMS[p][4] * 0.6) continue;
|
|
281
|
+
for (let m = 0; m < 2; m++) {
|
|
282
|
+
const u = 0.5 + m * 0.22 + 0.04 * p;
|
|
283
|
+
const x0 = CRYS[a * 3] + (CRYS[c * 3] - CRYS[a * 3]) * u, y0 = CRYS[a * 3 + 1] + (CRYS[c * 3 + 1] - CRYS[a * 3 + 1]) * u;
|
|
284
|
+
const x1 = CRYS[b2 * 3] + (CRYS[d * 3] - CRYS[b2 * 3]) * u, y1 = CRYS[b2 * 3 + 1] + (CRYS[d * 3 + 1] - CRYS[b2 * 3 + 1]) * u;
|
|
285
|
+
ctx.moveTo(x0 + (x1 - x0) * 0.18, y0 + (y1 - y0) * 0.18);
|
|
286
|
+
ctx.lineTo(x0 + (x1 - x0) * 0.82, y0 + (y1 - y0) * 0.82);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
ctx.stroke();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// a glint on the tallest tip
|
|
294
|
+
const gx = CRYS[12 * 3], gy = CRYS[12 * 3 + 1];
|
|
295
|
+
const g = r * (0.06 + 0.07 * k);
|
|
296
|
+
ctx.strokeStyle = grad(t, 0, 0.9);
|
|
297
|
+
ctx.beginPath();
|
|
298
|
+
ctx.moveTo(gx - g, gy); ctx.lineTo(gx + g, gy);
|
|
299
|
+
ctx.moveTo(gx, gy - g); ctx.lineTo(gx, gy + g);
|
|
300
|
+
ctx.stroke();
|
|
301
|
+
ctx.fillStyle = grad(t, 0, 0.95);
|
|
302
|
+
ctx.beginPath(); ctx.arc(gx, gy, clamp(r * 0.03, 0.8, 2.2), 0, TAU); ctx.fill();
|
|
303
|
+
ctx.restore();
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
/* ----------------------------------------------------------------- moon */
|
|
307
|
+
|
|
308
|
+
// longitude, latitude, size (in R). Seas are built from overlapping blobs so their edges are uneven.
|
|
309
|
+
// The first five are the big ones kept on tiny tiles.
|
|
310
|
+
const MARIA: readonly (readonly number[])[] = [
|
|
311
|
+
[-0.6, 0.12, 0.25], [-0.28, 0.5, 0.2], [0.34, 0.14, 0.17], [0.18, 0.44, 0.13], [-0.18, -0.36, 0.13],
|
|
312
|
+
[-0.48, -0.14, 0.18], [-0.74, 0.38, 0.14], [0.2, 0.0, 0.1], [0.58, -0.12, 0.11], [0.38, -0.27, 0.08],
|
|
313
|
+
[0.78, 0.3, 0.085], [-0.1, 0.62, 0.1], [-0.4, 0.3, 0.12],
|
|
314
|
+
];
|
|
315
|
+
// the first one is the bright young crater at the bottom with rays
|
|
316
|
+
const CRATERS: readonly (readonly number[])[] = [
|
|
317
|
+
[-0.2, -0.74, 0.06], [-0.36, 0.17, 0.055], [0.5, -0.5, 0.07], [0.1, -0.6, 0.05],
|
|
318
|
+
[-0.8, -0.42, 0.06], [0.68, 0.6, 0.05], [0.02, 0.82, 0.045], [-0.62, 0.14, 0.035],
|
|
319
|
+
];
|
|
320
|
+
|
|
321
|
+
/** Adds one foreshortened patch of the moon's surface to the path. Returns false when it is round the back. */
|
|
322
|
+
function moonPatch(ctx: Ctx, R: number, lon: number, lat: number, size: number, lon0: number, lat0: number, grow: number, ring: boolean) {
|
|
323
|
+
const la = lat + lat0, lo = lon + lon0;
|
|
324
|
+
const cla = Math.cos(la);
|
|
325
|
+
const z = cla * Math.cos(lo);
|
|
326
|
+
if (z < 0.04) return false;
|
|
327
|
+
const x = cla * Math.sin(lo) * R, y = -Math.sin(la) * R;
|
|
328
|
+
const rot = Math.atan2(y, x);
|
|
329
|
+
const ry = size * R * grow, rx = ry * Math.max(0.16, z);
|
|
330
|
+
if (ring) {
|
|
331
|
+
// the lit inner rim faces down-right, away from the light
|
|
332
|
+
const mid = Math.PI * 0.25 - rot;
|
|
333
|
+
ctx.moveTo(x + Math.cos(rot) * rx * Math.cos(mid - 1) - Math.sin(rot) * ry * Math.sin(mid - 1),
|
|
334
|
+
y + Math.sin(rot) * rx * Math.cos(mid - 1) + Math.cos(rot) * ry * Math.sin(mid - 1));
|
|
335
|
+
ctx.ellipse(x, y, rx, ry, rot, mid - 1, mid + 1);
|
|
336
|
+
} else {
|
|
337
|
+
ctx.moveTo(x + Math.cos(rot) * rx, y + Math.sin(rot) * rx);
|
|
338
|
+
ctx.ellipse(x, y, rx, ry, rot, 0, TAU);
|
|
339
|
+
}
|
|
340
|
+
return true;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const moon: IconDraw = (ctx, r, time, k, t) => {
|
|
344
|
+
halo(ctx, r, t, k, 0.32);
|
|
345
|
+
const R = r * (0.78 + 0.04 * k);
|
|
346
|
+
const lon0 = 0.2 * Math.sin(time * 0.29), lat0 = 0.11 * Math.sin(time * 0.21 + 1.3);
|
|
347
|
+
const lw = hair(r);
|
|
348
|
+
|
|
349
|
+
// the thin ring of light round a bright moon
|
|
350
|
+
if (r >= 18) {
|
|
351
|
+
ctx.strokeStyle = rampColor(t, 5, 0.12 + 0.12 * k);
|
|
352
|
+
ctx.lineWidth = lw;
|
|
353
|
+
ctx.beginPath(); ctx.arc(0, 0, R * 1.2, 0, TAU); ctx.stroke();
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// the body, brightest toward the upper left
|
|
357
|
+
ctx.beginPath(); ctx.arc(0, 0, R, 0, TAU);
|
|
358
|
+
if (r < 18) ctx.fillStyle = grad(t, 0.15, 0.95);
|
|
359
|
+
else {
|
|
360
|
+
const lx = -R * 0.22 + lon0 * R * 0.4, ly = -R * 0.24 - lat0 * R * 0.4;
|
|
361
|
+
const g = ctx.createRadialGradient(lx, ly, R * 0.05, 0, 0, R);
|
|
362
|
+
g.addColorStop(0, rampColor(t, 5, 1));
|
|
363
|
+
g.addColorStop(0.5, grad(t, 0.2, 0.97));
|
|
364
|
+
g.addColorStop(0.88, grad(t, 0.55, 0.94));
|
|
365
|
+
g.addColorStop(1, grad(t, 0.9, 0.86));
|
|
366
|
+
ctx.fillStyle = g;
|
|
367
|
+
}
|
|
368
|
+
ctx.fill();
|
|
369
|
+
|
|
370
|
+
ctx.save();
|
|
371
|
+
ctx.clip();
|
|
372
|
+
// soft dark seas: a wide faint pass, then a tighter one
|
|
373
|
+
const seas = r < 18 ? 5 : MARIA.length;
|
|
374
|
+
for (let pass = 0; pass < 2; pass++) {
|
|
375
|
+
ctx.fillStyle = shade(pass === 0 ? 0.07 : 0.12);
|
|
376
|
+
ctx.beginPath();
|
|
377
|
+
for (let i = 0; i < seas; i++) {
|
|
378
|
+
const m = MARIA[i];
|
|
379
|
+
moonPatch(ctx, R, m[0], m[1], m[2], lon0, lat0, pass === 0 ? 1.22 : 0.86, false);
|
|
380
|
+
}
|
|
381
|
+
ctx.fill();
|
|
382
|
+
}
|
|
383
|
+
if (r >= 18) {
|
|
384
|
+
const n = r < 42 ? 5 : CRATERS.length;
|
|
385
|
+
if (r >= 42) {
|
|
386
|
+
// rays thrown out by the young crater
|
|
387
|
+
const c = CRATERS[0], la = c[1] + lat0, lo = c[0] + lon0, cla = Math.cos(la);
|
|
388
|
+
if (cla * Math.cos(lo) > 0.04) {
|
|
389
|
+
const cx = cla * Math.sin(lo) * R, cy = -Math.sin(la) * R;
|
|
390
|
+
ctx.strokeStyle = light(0.13 + 0.06 * k);
|
|
391
|
+
ctx.lineWidth = lw * 0.8;
|
|
392
|
+
ctx.beginPath();
|
|
393
|
+
for (let i = 0; i < 9; i++) {
|
|
394
|
+
const a = -Math.PI * 0.5 + (i - 4) * 0.36 + 0.08 * Math.sin(i * 2.7), len = R * (0.35 + 0.4 * hashA(i + 4.2));
|
|
395
|
+
ctx.moveTo(cx + Math.cos(a) * R * 0.07, cy + Math.sin(a) * R * 0.07);
|
|
396
|
+
ctx.lineTo(cx + Math.cos(a) * len, cy + Math.sin(a) * len);
|
|
397
|
+
}
|
|
398
|
+
ctx.stroke();
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
ctx.fillStyle = shade(0.2);
|
|
402
|
+
ctx.beginPath();
|
|
403
|
+
for (let i = 0; i < n; i++) {
|
|
404
|
+
const c = CRATERS[i];
|
|
405
|
+
moonPatch(ctx, R, c[0], c[1], c[2], lon0, lat0, 1, false);
|
|
406
|
+
}
|
|
407
|
+
ctx.fill();
|
|
408
|
+
if (r >= 42) {
|
|
409
|
+
ctx.strokeStyle = light(0.34 + 0.16 * k);
|
|
410
|
+
ctx.lineWidth = lw * 0.9;
|
|
411
|
+
ctx.beginPath();
|
|
412
|
+
for (let i = 0; i < n; i++) {
|
|
413
|
+
const c = CRATERS[i];
|
|
414
|
+
moonPatch(ctx, R, c[0], c[1], c[2], lon0, lat0, 1, true);
|
|
415
|
+
}
|
|
416
|
+
ctx.stroke();
|
|
417
|
+
}
|
|
418
|
+
// the edge darkens a little, like a real limb
|
|
419
|
+
const limb = ctx.createRadialGradient(0, 0, R * 0.55, 0, 0, R);
|
|
420
|
+
limb.addColorStop(0, shade(0));
|
|
421
|
+
limb.addColorStop(1, shade(0.28));
|
|
422
|
+
ctx.fillStyle = limb;
|
|
423
|
+
ctx.fillRect(-R, -R, R * 2, R * 2);
|
|
424
|
+
}
|
|
425
|
+
ctx.restore();
|
|
426
|
+
|
|
427
|
+
ctx.strokeStyle = grad(t, 0, 0.36 + 0.26 * k);
|
|
428
|
+
ctx.lineWidth = lw;
|
|
429
|
+
ctx.beginPath(); ctx.arc(0, 0, R, 0, TAU); ctx.stroke();
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
/* ------------------------------------------------------------- pinecone */
|
|
433
|
+
|
|
434
|
+
const GOLDEN = Math.PI * (3 - Math.sqrt(5));
|
|
435
|
+
/** Half-width of the cone at height h (0 = bottom tip, 1 = top): an egg, widest a little above the middle. */
|
|
436
|
+
const coneWidth = (h: number) => Math.pow(Math.sin(Math.PI * (1 - Math.pow(1 - clamp01(h), 0.72))), 0.72);
|
|
437
|
+
|
|
438
|
+
const pinecone: IconDraw = (ctx, r, time, k, t) => {
|
|
439
|
+
halo(ctx, r, t, k, 0.24);
|
|
440
|
+
const N = r < 18 ? 30 : r < 42 ? 56 : 88;
|
|
441
|
+
const H = r * 1.66, W = r * 0.56 * (1 + 0.02 * k);
|
|
442
|
+
const spin = time * 0.4;
|
|
443
|
+
const cell = Math.sqrt((TAU * W * 0.62 * H) / N) * 0.8;
|
|
444
|
+
const lw = hair(r);
|
|
445
|
+
ctx.save();
|
|
446
|
+
ctx.rotate(0.2 + 0.05 * Math.sin(time * 0.5));
|
|
447
|
+
ctx.translate(0, r * 0.05);
|
|
448
|
+
|
|
449
|
+
// silhouette
|
|
450
|
+
if (r >= 18) {
|
|
451
|
+
ctx.strokeStyle = grad(t, 1, 0.24 + 0.1 * k);
|
|
452
|
+
ctx.lineWidth = lw;
|
|
453
|
+
ctx.beginPath();
|
|
454
|
+
for (let i = 0; i <= 24; i++) {
|
|
455
|
+
const h = i / 24, y = (0.5 - h) * H, x = coneWidth(h) * W * 1.1;
|
|
456
|
+
i === 0 ? ctx.moveTo(x, y) : ctx.lineTo(x, y);
|
|
457
|
+
}
|
|
458
|
+
for (let i = 24; i >= 0; i--) {
|
|
459
|
+
const h = i / 24;
|
|
460
|
+
ctx.lineTo(-coneWidth(h) * W * 1.1, (0.5 - h) * H);
|
|
461
|
+
}
|
|
462
|
+
ctx.stroke();
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// scales on crossing golden-angle spirals, lit from the upper left
|
|
466
|
+
const umbo = r >= 42;
|
|
467
|
+
for (let b = 0; b < 4; b++) {
|
|
468
|
+
const f = (b + 0.5) / 4;
|
|
469
|
+
ctx.fillStyle = grad(t, 1 - f, 0.4 + 0.56 * f);
|
|
470
|
+
ctx.beginPath();
|
|
471
|
+
for (let i = 0; i < N; i++) {
|
|
472
|
+
const th = i * GOLDEN + spin;
|
|
473
|
+
const z = Math.cos(th);
|
|
474
|
+
if (z < 0.02) continue;
|
|
475
|
+
const h = (i + 0.5) / N;
|
|
476
|
+
const sn = Math.sin(th);
|
|
477
|
+
if (bucket(0.16 + 0.72 * z - 0.3 * sn + 0.2 * (h - 0.5)) !== b) continue;
|
|
478
|
+
const rho = coneWidth(h);
|
|
479
|
+
const x = sn * rho * W, y = (0.5 - h) * H;
|
|
480
|
+
const sz = cell * (0.35 + 0.65 * rho) * (0.94 + 0.1 * k);
|
|
481
|
+
const hw = Math.max(0.5, sz * (0.3 + 0.78 * z));
|
|
482
|
+
const hh = sz * 0.7;
|
|
483
|
+
// a wide diamond, point hanging down
|
|
484
|
+
ctx.moveTo(x, y - hh * 0.72);
|
|
485
|
+
ctx.lineTo(x + hw, y - hh * 0.05);
|
|
486
|
+
ctx.lineTo(x, y + hh);
|
|
487
|
+
ctx.lineTo(x - hw, y - hh * 0.05);
|
|
488
|
+
ctx.closePath();
|
|
489
|
+
}
|
|
490
|
+
ctx.fill();
|
|
491
|
+
}
|
|
492
|
+
if (umbo) {
|
|
493
|
+
// the little boss at the centre of each scale
|
|
494
|
+
ctx.fillStyle = shade(0.4);
|
|
495
|
+
ctx.beginPath();
|
|
496
|
+
for (let i = 0; i < N; i++) {
|
|
497
|
+
const th = i * GOLDEN + spin;
|
|
498
|
+
const z = Math.cos(th);
|
|
499
|
+
if (z < 0.3) continue;
|
|
500
|
+
const h = (i + 0.5) / N, rho = coneWidth(h);
|
|
501
|
+
const x = Math.sin(th) * rho * W, y = (0.5 - h) * H;
|
|
502
|
+
const sz = cell * (0.35 + 0.65 * rho);
|
|
503
|
+
const d = Math.max(0.6, sz * 0.13 * z);
|
|
504
|
+
ctx.moveTo(x + d, y + sz * 0.16); ctx.arc(x, y + sz * 0.16, d, 0, TAU);
|
|
505
|
+
}
|
|
506
|
+
ctx.fill();
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// stem
|
|
510
|
+
ctx.strokeStyle = grad(t, 0, 0.75);
|
|
511
|
+
ctx.lineWidth = clamp(r * 0.03, 0.8, 2);
|
|
512
|
+
ctx.beginPath();
|
|
513
|
+
ctx.moveTo(0, -H * 0.5 + r * 0.04);
|
|
514
|
+
ctx.quadraticCurveTo(r * 0.02, -H * 0.5 - r * 0.1, r * 0.12, -H * 0.5 - r * 0.16);
|
|
515
|
+
ctx.stroke();
|
|
516
|
+
ctx.restore();
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
/* -------------------------------------------------------------- ripples */
|
|
520
|
+
|
|
521
|
+
// where the drops fall (in R) and how their rings run
|
|
522
|
+
const SOURCES: readonly (readonly number[])[] = [
|
|
523
|
+
[-0.34, -0.24, 0.0, 0.3],
|
|
524
|
+
[0.32, 0.26, 0.43, 0.26],
|
|
525
|
+
];
|
|
526
|
+
|
|
527
|
+
const ripples: IconDraw = (ctx, r, time, k, t) => {
|
|
528
|
+
halo(ctx, r, t, k, 0.22);
|
|
529
|
+
const R = r * (0.92 + 0.03 * k);
|
|
530
|
+
const lw = hair(r);
|
|
531
|
+
const rings = r < 18 ? 3 : r < 42 ? 4 : 5;
|
|
532
|
+
const reach = R * 1.5;
|
|
533
|
+
ctx.save();
|
|
534
|
+
ctx.beginPath(); ctx.arc(0, 0, R, 0, TAU); ctx.clip();
|
|
535
|
+
ctx.fillStyle = grad(t, 1, 0.08 + 0.04 * k);
|
|
536
|
+
ctx.fillRect(-R, -R, R * 2, R * 2);
|
|
537
|
+
|
|
538
|
+
// rings: fresh ones thick and bright, old ones thin and faint
|
|
539
|
+
for (let b = 0; b < 4; b++) {
|
|
540
|
+
const f = (b + 0.5) / 4;
|
|
541
|
+
ctx.strokeStyle = grad(t, 1 - f, 0.24 + 0.7 * f);
|
|
542
|
+
ctx.lineWidth = lw * (0.7 + 0.9 * f);
|
|
543
|
+
ctx.beginPath();
|
|
544
|
+
for (let si = 0; si < 2; si++) {
|
|
545
|
+
const S = SOURCES[si], sx = S[0] * R, sy = S[1] * R;
|
|
546
|
+
const out = R + Math.sqrt(sx * sx + sy * sy);
|
|
547
|
+
const clock = time * S[3] + S[2];
|
|
548
|
+
for (let j = 0; j < rings; j++) {
|
|
549
|
+
const p = frac(clock + j / rings);
|
|
550
|
+
const fade = Math.pow(1 - p, 1.3) * clamp01(p / 0.05);
|
|
551
|
+
const rad = p * reach;
|
|
552
|
+
if (fade < 0.03 || rad * 0.86 - lw * 1.5 > out) continue; // gone, or wholly outside the window
|
|
553
|
+
if (bucket(fade) === b && rad > 0.5 && rad < out) { ctx.moveTo(sx + rad, sy); ctx.arc(sx, sy, rad, 0, TAU); }
|
|
554
|
+
if (r >= 42 && fade > 0.3 && rad > lw * 4 && bucket(fade * 0.5) === b) {
|
|
555
|
+
const inner = rad * 0.86 - lw * 1.5;
|
|
556
|
+
ctx.moveTo(sx + inner, sy); ctx.arc(sx, sy, inner, 0, TAU);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
ctx.stroke();
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// where two rings cross, the water lifts: a bright bead
|
|
564
|
+
if (r >= 18) {
|
|
565
|
+
const A = SOURCES[0], B = SOURCES[1];
|
|
566
|
+
const ax = A[0] * R, ay = A[1] * R, bx = B[0] * R, by = B[1] * R;
|
|
567
|
+
const dx = bx - ax, dy = by - ay, d = Math.sqrt(dx * dx + dy * dy), ux = dx / d, uy = dy / d;
|
|
568
|
+
const ca = time * A[3] + A[2], cb = time * B[3] + B[2];
|
|
569
|
+
for (let band = 2; band < 4; band++) {
|
|
570
|
+
ctx.fillStyle = band === 3 ? grad(t, 0, 0.95) : grad(t, 0.3, 0.6);
|
|
571
|
+
ctx.beginPath();
|
|
572
|
+
for (let i = 0; i < rings; i++) {
|
|
573
|
+
const pa = frac(ca + i / rings), r0 = pa * reach, fa = Math.pow(1 - pa, 1.3);
|
|
574
|
+
for (let j = 0; j < rings; j++) {
|
|
575
|
+
const pb = frac(cb + j / rings), r1 = pb * reach, fb = Math.pow(1 - pb, 1.3);
|
|
576
|
+
const v = Math.min(fa, fb);
|
|
577
|
+
if (bucket(v) !== band) continue;
|
|
578
|
+
const a = (r0 * r0 - r1 * r1 + d * d) / (2 * d);
|
|
579
|
+
const h2 = r0 * r0 - a * a;
|
|
580
|
+
if (h2 <= 0) continue;
|
|
581
|
+
const h = Math.sqrt(h2), mx = ax + ux * a, my = ay + uy * a;
|
|
582
|
+
const dot = Math.max(0.7, lw * (0.8 + 1.4 * v));
|
|
583
|
+
for (let sgn = -1; sgn <= 1; sgn += 2) {
|
|
584
|
+
const px = mx - uy * h * sgn, py = my + ux * h * sgn;
|
|
585
|
+
if (px * px + py * py > R * R) continue;
|
|
586
|
+
ctx.moveTo(px + dot, py); ctx.arc(px, py, dot, 0, TAU);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
ctx.fill();
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
// the drops themselves: one falls, hits, and the dot flares
|
|
595
|
+
ctx.fillStyle = grad(t, 0, 0.92);
|
|
596
|
+
ctx.beginPath();
|
|
597
|
+
for (let si = 0; si < 2; si++) {
|
|
598
|
+
const S = SOURCES[si], sx = S[0] * R, sy = S[1] * R;
|
|
599
|
+
const q = frac((time * S[3] + S[2]) * rings);
|
|
600
|
+
const flare = q < 0.25 ? 1 - q / 0.25 : 0;
|
|
601
|
+
const dot = clamp(r * 0.035, 0.8, 2.6) * (1 + 1.2 * flare);
|
|
602
|
+
ctx.moveTo(sx + dot, sy); ctx.arc(sx, sy, dot, 0, TAU);
|
|
603
|
+
if (q > 0.7 && r >= 18) {
|
|
604
|
+
const fallY = sy - ((1 - q) / 0.3) * R * 0.4, dd = clamp(r * 0.025, 0.7, 2);
|
|
605
|
+
ctx.moveTo(sx + dd, fallY); ctx.arc(sx, fallY, dd, 0, TAU);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
ctx.fill();
|
|
609
|
+
ctx.restore();
|
|
610
|
+
|
|
611
|
+
ctx.strokeStyle = grad(t, 0, 0.42 + 0.24 * k);
|
|
612
|
+
ctx.lineWidth = clamp(r * 0.025, 0.75, 1.8);
|
|
613
|
+
ctx.beginPath(); ctx.arc(0, 0, R, 0, TAU); ctx.stroke();
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
/* ------------------------------------------------------------- mushroom */
|
|
617
|
+
|
|
618
|
+
// spots on the cap: across (-1..1 of the cap), up (0..1 of its height), size (in r)
|
|
619
|
+
const SPOTS: readonly (readonly number[])[] = [
|
|
620
|
+
[-0.42, 0.58, 0.12], [0.08, 0.8, 0.14], [0.5, 0.5, 0.1], [-0.08, 0.36, 0.08],
|
|
621
|
+
[0.3, 0.22, 0.07], [-0.7, 0.24, 0.07], [0.74, 0.16, 0.055],
|
|
622
|
+
];
|
|
623
|
+
|
|
624
|
+
const mushroom: IconDraw = (ctx, r, time, k, t) => {
|
|
625
|
+
const C = t.colors;
|
|
626
|
+
halo(ctx, r, t, k, 0.3);
|
|
627
|
+
const lw = hair(r);
|
|
628
|
+
const a = r * 0.86, capH = r * (0.6 + 0.015 * k), y0 = -r * 0.06, under = a * 0.2;
|
|
629
|
+
const foot = r * 0.8, sTop = r * 0.15, sFoot = r * 0.2;
|
|
630
|
+
const rich = r >= 18;
|
|
631
|
+
ctx.save();
|
|
632
|
+
// a slow sway from the foot
|
|
633
|
+
ctx.translate(0, foot);
|
|
634
|
+
ctx.rotate(0.06 * Math.sin(time * 0.55));
|
|
635
|
+
ctx.translate(0, -foot);
|
|
636
|
+
|
|
637
|
+
// light pooled on the ground
|
|
638
|
+
ctx.fillStyle = grad(t, 1, 0.14 + 0.08 * k);
|
|
639
|
+
ctx.beginPath(); ctx.ellipse(0, foot, r * 0.46, r * 0.07, 0, 0, TAU); ctx.fill();
|
|
640
|
+
|
|
641
|
+
// the glowing underside and its gills
|
|
642
|
+
ctx.beginPath();
|
|
643
|
+
ctx.moveTo(-a * 0.97, y0);
|
|
644
|
+
ctx.ellipse(0, y0, a * 0.97, under, 0, Math.PI, 0, true);
|
|
645
|
+
ctx.closePath();
|
|
646
|
+
ctx.fillStyle = grad(t, 1, 0.55 + 0.3 * k);
|
|
647
|
+
ctx.fill();
|
|
648
|
+
if (rich) {
|
|
649
|
+
const gills = r < 42 ? 9 : 15;
|
|
650
|
+
ctx.strokeStyle = shade(0.42);
|
|
651
|
+
ctx.lineWidth = lw * 0.8;
|
|
652
|
+
ctx.beginPath();
|
|
653
|
+
for (let i = 0; i < gills; i++) {
|
|
654
|
+
const th = Math.PI * (0.06 + 0.88 * (i + 0.5) / gills);
|
|
655
|
+
ctx.moveTo(0, y0 + under * 0.15);
|
|
656
|
+
ctx.lineTo(Math.cos(th) * a * 0.93, y0 + Math.sin(th) * under * 0.93);
|
|
657
|
+
}
|
|
658
|
+
ctx.stroke();
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// stem
|
|
662
|
+
const yTop = y0 + under * 0.4, mid = (yTop + foot) * 0.5;
|
|
663
|
+
ctx.beginPath();
|
|
664
|
+
ctx.moveTo(-sTop, yTop);
|
|
665
|
+
ctx.quadraticCurveTo(-sTop * 1.25, mid, -sFoot, foot);
|
|
666
|
+
ctx.quadraticCurveTo(0, foot + r * 0.05, sFoot, foot);
|
|
667
|
+
ctx.quadraticCurveTo(sTop * 1.25, mid, sTop, yTop);
|
|
668
|
+
ctx.closePath();
|
|
669
|
+
if (rich) {
|
|
670
|
+
const g = ctx.createLinearGradient(-sFoot, 0, sFoot, 0);
|
|
671
|
+
g.addColorStop(0, rampColor(t, 5, 0.95));
|
|
672
|
+
g.addColorStop(0.55, grad(t, 1, 0.85));
|
|
673
|
+
g.addColorStop(1, grad(t, 1, 0.42));
|
|
674
|
+
ctx.fillStyle = g;
|
|
675
|
+
} else ctx.fillStyle = grad(t, 1, 0.85);
|
|
676
|
+
ctx.fill();
|
|
677
|
+
|
|
678
|
+
// the cap
|
|
679
|
+
ctx.beginPath();
|
|
680
|
+
ctx.ellipse(0, y0, a, capH, 0, Math.PI, 0);
|
|
681
|
+
ctx.ellipse(0, y0, a, under * 0.35, 0, 0, Math.PI);
|
|
682
|
+
ctx.closePath();
|
|
683
|
+
if (rich) {
|
|
684
|
+
const gx = -a * 0.3, gy = y0 - capH * 0.62;
|
|
685
|
+
const g = ctx.createRadialGradient(gx, gy, r * 0.04, gx, gy, a * 1.25);
|
|
686
|
+
g.addColorStop(0, rampColor(t, 5, 1));
|
|
687
|
+
g.addColorStop(0.42, C.primary);
|
|
688
|
+
g.addColorStop(0.8, C.secondary);
|
|
689
|
+
g.addColorStop(1, C.accent);
|
|
690
|
+
ctx.fillStyle = g;
|
|
691
|
+
} else ctx.fillStyle = C.primary;
|
|
692
|
+
ctx.fill();
|
|
693
|
+
ctx.strokeStyle = rampColor(t, 5, 0.5 + 0.3 * k);
|
|
694
|
+
ctx.lineWidth = lw;
|
|
695
|
+
ctx.stroke();
|
|
696
|
+
|
|
697
|
+
// spots, squeezed toward the sides of the dome
|
|
698
|
+
const nSpots = r < 18 ? 3 : r < 42 ? 5 : SPOTS.length;
|
|
699
|
+
ctx.fillStyle = light(0.5 + 0.15 * k);
|
|
700
|
+
ctx.beginPath();
|
|
701
|
+
for (let i = 0; i < nSpots; i++) {
|
|
702
|
+
const S = SPOTS[i];
|
|
703
|
+
const x = S[0] * a * Math.sqrt(1 - S[1] * S[1] * 0.6), y = y0 - S[1] * capH;
|
|
704
|
+
const ry = S[2] * r * (1 - S[1] * 0.35), rx = S[2] * r * Math.sqrt(1 - S[0] * S[0] * 0.7);
|
|
705
|
+
ctx.moveTo(x + rx, y); ctx.ellipse(x, y, rx, ry, 0, 0, TAU);
|
|
706
|
+
}
|
|
707
|
+
ctx.fill();
|
|
708
|
+
|
|
709
|
+
// spores drifting up
|
|
710
|
+
const spores = r < 18 ? 3 : r < 42 ? 7 : 12;
|
|
711
|
+
for (let b = 0; b < 4; b++) {
|
|
712
|
+
const f = (b + 0.5) / 4;
|
|
713
|
+
ctx.fillStyle = grad(t, f * 0.6, 0.3 + 0.66 * f);
|
|
714
|
+
ctx.beginPath();
|
|
715
|
+
for (let i = 0; i < spores; i++) {
|
|
716
|
+
const p = frac(time * 0.2 + hashA(i + 0.7));
|
|
717
|
+
const v = Math.sin(p * Math.PI);
|
|
718
|
+
if (bucket(v) !== b) continue;
|
|
719
|
+
const x = (hashB(i + 2.3) * 2 - 1) * a * 1.02 + Math.sin(time * 0.8 + i * 2.1) * r * 0.08 * p;
|
|
720
|
+
const y = y0 + under * 0.6 - p * r * 1.05;
|
|
721
|
+
const d = Math.max(0.55, r * 0.018 * (1 + hashA(i + 9.1)) * (1 - 0.4 * p));
|
|
722
|
+
ctx.moveTo(x + d, y); ctx.arc(x, y, d, 0, TAU);
|
|
723
|
+
}
|
|
724
|
+
ctx.fill();
|
|
725
|
+
}
|
|
726
|
+
ctx.restore();
|
|
727
|
+
};
|
|
728
|
+
|
|
729
|
+
/* ----------------------------------------------------------------- leaf */
|
|
730
|
+
|
|
731
|
+
/** Leaf half-width at u (0 = base, 1 = tip), widest a little below the middle. */
|
|
732
|
+
const leafWidth = (u: number) => (u <= 0 || u >= 1 ? 0 : Math.pow(Math.sin(Math.PI * Math.pow(u, 0.82)), 0.85));
|
|
733
|
+
|
|
734
|
+
/** Brightness of the light pulse at distance d along the veins. */
|
|
735
|
+
const veinLight = (d: number, front: number) => {
|
|
736
|
+
const x = (d - front) / 0.11;
|
|
737
|
+
return Math.exp(-x * x);
|
|
738
|
+
};
|
|
739
|
+
|
|
740
|
+
const leaf: IconDraw = (ctx, r, time, k, t) => {
|
|
741
|
+
halo(ctx, r, t, k, 0.22);
|
|
742
|
+
const lw = hair(r);
|
|
743
|
+
const L = r * 1.52, x0 = -r * 0.7, W = r * 0.5;
|
|
744
|
+
const bend = 0.06 * Math.sin(time * 0.9);
|
|
745
|
+
const twist = 0.12 * Math.sin(time * 0.8);
|
|
746
|
+
const sideUp = 0.93 + twist, sideDown = 0.93 - twist;
|
|
747
|
+
const front = frac(time * 0.3) * 1.6 - 0.25;
|
|
748
|
+
const S = r < 18 ? 12 : 20;
|
|
749
|
+
const X = (u: number) => x0 + u * L;
|
|
750
|
+
const Y = (u: number) => bend * L * Math.sin(Math.PI * u);
|
|
751
|
+
|
|
752
|
+
ctx.save();
|
|
753
|
+
ctx.rotate(-0.72 + 0.05 * Math.sin(time * 1.3) + 0.025 * Math.sin(time * 2.9));
|
|
754
|
+
|
|
755
|
+
// blade
|
|
756
|
+
ctx.beginPath();
|
|
757
|
+
for (let i = 0; i <= S; i++) {
|
|
758
|
+
const u = i / S;
|
|
759
|
+
const x = X(u), y = Y(u) - leafWidth(u) * W * sideUp;
|
|
760
|
+
i === 0 ? ctx.moveTo(x, y) : ctx.lineTo(x, y);
|
|
761
|
+
}
|
|
762
|
+
for (let i = S; i >= 0; i--) {
|
|
763
|
+
const u = i / S;
|
|
764
|
+
ctx.lineTo(X(u), Y(u) + leafWidth(u) * W * sideDown);
|
|
765
|
+
}
|
|
766
|
+
ctx.closePath();
|
|
767
|
+
ctx.fillStyle = grad(t, 1, 0.1 + 0.05 * k);
|
|
768
|
+
ctx.fill();
|
|
769
|
+
ctx.strokeStyle = grad(t, 0, 0.5 + 0.24 * k);
|
|
770
|
+
ctx.lineWidth = lw;
|
|
771
|
+
ctx.stroke();
|
|
772
|
+
|
|
773
|
+
// midrib and side veins, each cut in short pieces so the light can run along them
|
|
774
|
+
const pairs = r < 18 ? 4 : r < 42 ? 6 : 9;
|
|
775
|
+
const M = r < 18 ? 8 : r < 42 ? 12 : 18;
|
|
776
|
+
const steps = r < 18 ? 2 : r < 42 ? 3 : 5;
|
|
777
|
+
for (let pass = 0; pass < 2; pass++) {
|
|
778
|
+
for (let b = 0; b < 4; b++) {
|
|
779
|
+
const f = (b + 0.5) / 4;
|
|
780
|
+
ctx.strokeStyle = grad(t, 1 - f, 0.3 + 0.66 * f);
|
|
781
|
+
ctx.lineWidth = pass === 0 ? lw * (1.15 + 0.5 * f) : lw * (0.75 + 0.4 * f);
|
|
782
|
+
ctx.beginPath();
|
|
783
|
+
if (pass === 0) {
|
|
784
|
+
for (let i = 0; i < M; i++) {
|
|
785
|
+
const u0 = -0.18 + (1.15 * i) / M, u1 = -0.18 + (1.15 * (i + 1)) / M;
|
|
786
|
+
if (bucket(0.16 + 0.84 * veinLight((u0 + u1) * 0.5, front)) !== b) continue;
|
|
787
|
+
ctx.moveTo(X(u0), Y(Math.max(0, u0))); ctx.lineTo(X(u1), Y(Math.max(0, u1)));
|
|
788
|
+
}
|
|
789
|
+
} else {
|
|
790
|
+
for (let i = 0; i < pairs; i++) {
|
|
791
|
+
const ui = 0.08 + (0.78 * (i + 0.3)) / pairs, ue = Math.min(0.97, ui + 0.17);
|
|
792
|
+
const uc = ui + 0.05;
|
|
793
|
+
for (let side = -1; side <= 1; side += 2) {
|
|
794
|
+
const sc = side < 0 ? sideUp : sideDown;
|
|
795
|
+
const px = X(ui), py = Y(ui);
|
|
796
|
+
const cx = X(uc), cy = Y(uc) + side * leafWidth(uc) * W * sc * 0.45;
|
|
797
|
+
const ex = X(ue), ey = Y(ue) + side * leafWidth(ue) * W * sc * 0.88;
|
|
798
|
+
let lx = px, ly = py;
|
|
799
|
+
for (let s = 1; s <= steps; s++) {
|
|
800
|
+
const q = s / steps, iq = 1 - q;
|
|
801
|
+
const qx = iq * iq * px + 2 * iq * q * cx + q * q * ex;
|
|
802
|
+
const qy = iq * iq * py + 2 * iq * q * cy + q * q * ey;
|
|
803
|
+
const d = ui + (q - 0.5 / steps) * 0.3;
|
|
804
|
+
if (bucket(0.1 + 0.9 * veinLight(d, front)) === b) { ctx.moveTo(lx, ly); ctx.lineTo(qx, qy); }
|
|
805
|
+
lx = qx; ly = qy;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
ctx.stroke();
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
// the bead of light at the front of the pulse, running up the midrib
|
|
814
|
+
if (r >= 18 && front > 0 && front < 0.96) {
|
|
815
|
+
const bx = X(front), by = Y(front);
|
|
816
|
+
const glow = Math.sin((front / 0.96) * Math.PI);
|
|
817
|
+
ctx.fillStyle = grad(t, 0, 0.22 * glow);
|
|
818
|
+
ctx.beginPath(); ctx.arc(bx, by, lw * 4.2, 0, TAU); ctx.fill();
|
|
819
|
+
ctx.fillStyle = grad(t, 0, 0.95 * glow);
|
|
820
|
+
ctx.beginPath(); ctx.arc(bx, by, lw * 1.5, 0, TAU); ctx.fill();
|
|
821
|
+
}
|
|
822
|
+
ctx.restore();
|
|
823
|
+
};
|
|
824
|
+
|
|
825
|
+
export const iconsB: Record<'sun' | 'rain' | 'crystal' | 'moon' | 'pinecone' | 'ripples' | 'mushroom' | 'leaf', IconDraw> = {
|
|
826
|
+
sun, rain, crystal, moon, pinecone, ripples, mushroom, leaf,
|
|
827
|
+
};
|