@basmilius/sparkle 1.0.0 → 2.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.
Files changed (148) hide show
  1. package/dist/index.d.mts +1192 -14
  2. package/dist/index.d.mts.map +1 -1
  3. package/dist/index.mjs +4552 -370
  4. package/dist/index.mjs.map +1 -1
  5. package/package.json +3 -2
  6. package/src/aurora/consts.ts +3 -0
  7. package/src/aurora/index.ts +4 -0
  8. package/src/aurora/layer.ts +152 -0
  9. package/src/aurora/simulation.ts +19 -0
  10. package/src/aurora/types.ts +13 -0
  11. package/src/balloons/consts.ts +3 -0
  12. package/src/balloons/index.ts +6 -0
  13. package/src/balloons/layer.ts +138 -0
  14. package/src/balloons/particle.ts +110 -0
  15. package/src/balloons/simulation.ts +19 -0
  16. package/src/balloons/types.ts +14 -0
  17. package/src/bubbles/consts.ts +3 -0
  18. package/src/bubbles/index.ts +4 -0
  19. package/src/bubbles/layer.ts +233 -0
  20. package/src/bubbles/simulation.ts +20 -0
  21. package/src/bubbles/types.ts +21 -0
  22. package/src/canvas.ts +20 -1
  23. package/src/color.ts +10 -0
  24. package/src/confetti/consts.ts +13 -13
  25. package/src/confetti/index.ts +6 -0
  26. package/src/confetti/layer.ts +152 -0
  27. package/src/confetti/particle.ts +105 -0
  28. package/src/confetti/shapes.ts +104 -0
  29. package/src/confetti/simulation.ts +9 -203
  30. package/src/confetti/types.ts +4 -1
  31. package/src/distance.ts +1 -1
  32. package/src/donuts/consts.ts +19 -0
  33. package/src/donuts/donut.ts +12 -0
  34. package/src/donuts/index.ts +3 -0
  35. package/src/donuts/layer.ts +270 -0
  36. package/src/donuts/simulation.ts +25 -0
  37. package/src/fireflies/consts.ts +3 -0
  38. package/src/fireflies/index.ts +6 -0
  39. package/src/fireflies/layer.ts +152 -0
  40. package/src/fireflies/particle.ts +124 -0
  41. package/src/fireflies/simulation.ts +18 -0
  42. package/src/fireflies/types.ts +17 -0
  43. package/src/firepit/consts.ts +3 -0
  44. package/src/firepit/index.ts +4 -0
  45. package/src/firepit/layer.ts +174 -0
  46. package/src/firepit/simulation.ts +17 -0
  47. package/src/firepit/types.ts +20 -0
  48. package/src/fireworks/explosion.ts +8 -8
  49. package/src/fireworks/firework.ts +9 -8
  50. package/src/fireworks/index.ts +6 -2
  51. package/src/fireworks/layer.ts +452 -0
  52. package/src/fireworks/simulation.ts +9 -484
  53. package/src/fireworks/spark.ts +7 -7
  54. package/src/glitter/consts.ts +13 -0
  55. package/src/glitter/index.ts +4 -0
  56. package/src/glitter/layer.ts +173 -0
  57. package/src/glitter/simulation.ts +19 -0
  58. package/src/glitter/types.ts +23 -0
  59. package/src/index.ts +28 -0
  60. package/src/lanterns/consts.ts +13 -0
  61. package/src/lanterns/index.ts +4 -0
  62. package/src/lanterns/layer.ts +166 -0
  63. package/src/lanterns/simulation.ts +17 -0
  64. package/src/lanterns/types.ts +14 -0
  65. package/src/layer.ts +24 -0
  66. package/src/layered.ts +185 -0
  67. package/src/leaves/consts.ts +16 -0
  68. package/src/leaves/index.ts +4 -0
  69. package/src/leaves/layer.ts +251 -0
  70. package/src/leaves/simulation.ts +18 -0
  71. package/src/leaves/types.ts +16 -0
  72. package/src/lightning/consts.ts +3 -0
  73. package/src/lightning/index.ts +6 -0
  74. package/src/lightning/layer.ts +41 -0
  75. package/src/lightning/simulation.ts +17 -0
  76. package/src/lightning/system.ts +196 -0
  77. package/src/lightning/types.ts +12 -0
  78. package/src/matrix/consts.ts +5 -0
  79. package/src/matrix/index.ts +4 -0
  80. package/src/matrix/layer.ts +146 -0
  81. package/src/matrix/simulation.ts +18 -0
  82. package/src/matrix/types.ts +8 -0
  83. package/src/orbits/consts.ts +13 -0
  84. package/src/orbits/index.ts +4 -0
  85. package/src/orbits/layer.ts +183 -0
  86. package/src/orbits/simulation.ts +19 -0
  87. package/src/orbits/types.ts +16 -0
  88. package/src/particles/consts.ts +3 -0
  89. package/src/particles/index.ts +4 -0
  90. package/src/particles/layer.ts +317 -0
  91. package/src/particles/simulation.ts +26 -0
  92. package/src/particles/types.ts +10 -0
  93. package/src/petals/consts.ts +13 -0
  94. package/src/petals/index.ts +4 -0
  95. package/src/petals/layer.ts +158 -0
  96. package/src/petals/simulation.ts +18 -0
  97. package/src/petals/types.ts +15 -0
  98. package/src/plasma/consts.ts +3 -0
  99. package/src/plasma/index.ts +4 -0
  100. package/src/plasma/layer.ts +92 -0
  101. package/src/plasma/simulation.ts +17 -0
  102. package/src/plasma/types.ts +5 -0
  103. package/src/rain/consts.ts +3 -0
  104. package/src/rain/index.ts +6 -0
  105. package/src/rain/layer.ts +172 -0
  106. package/src/rain/particle.ts +132 -0
  107. package/src/rain/simulation.ts +21 -0
  108. package/src/rain/types.ts +22 -0
  109. package/src/sandstorm/consts.ts +3 -0
  110. package/src/sandstorm/index.ts +4 -0
  111. package/src/sandstorm/layer.ts +135 -0
  112. package/src/sandstorm/simulation.ts +18 -0
  113. package/src/sandstorm/types.ts +10 -0
  114. package/src/shooting-stars/index.ts +3 -0
  115. package/src/shooting-stars/system.ts +149 -0
  116. package/src/shooting-stars/types.ts +10 -0
  117. package/src/simulation-canvas.ts +47 -0
  118. package/src/snow/consts.ts +2 -2
  119. package/src/snow/index.ts +1 -0
  120. package/src/snow/layer.ts +263 -0
  121. package/src/snow/simulation.ts +4 -288
  122. package/src/sparklers/consts.ts +3 -0
  123. package/src/sparklers/index.ts +6 -0
  124. package/src/sparklers/layer.ts +174 -0
  125. package/src/sparklers/particle.ts +89 -0
  126. package/src/sparklers/simulation.ts +30 -0
  127. package/src/sparklers/types.ts +13 -0
  128. package/src/stars/consts.ts +3 -0
  129. package/src/stars/index.ts +4 -0
  130. package/src/stars/layer.ts +133 -0
  131. package/src/stars/simulation.ts +22 -0
  132. package/src/stars/types.ts +12 -0
  133. package/src/streamers/consts.ts +14 -0
  134. package/src/streamers/index.ts +4 -0
  135. package/src/streamers/layer.ts +211 -0
  136. package/src/streamers/simulation.ts +16 -0
  137. package/src/streamers/types.ts +14 -0
  138. package/src/trail.ts +140 -0
  139. package/src/waves/consts.ts +3 -0
  140. package/src/waves/index.ts +4 -0
  141. package/src/waves/layer.ts +167 -0
  142. package/src/waves/simulation.ts +18 -0
  143. package/src/waves/types.ts +9 -0
  144. package/src/wormhole/consts.ts +3 -0
  145. package/src/wormhole/index.ts +4 -0
  146. package/src/wormhole/layer.ts +181 -0
  147. package/src/wormhole/simulation.ts +17 -0
  148. package/src/wormhole/types.ts +10 -0
@@ -0,0 +1,149 @@
1
+ import type { ShootingStar } from './types';
2
+
3
+ export interface ShootingStarSystemConfig {
4
+ readonly interval: [number, number];
5
+ readonly color?: [number, number, number];
6
+ readonly trailLength?: number;
7
+ readonly trailAlphaFactor?: number;
8
+ readonly speed?: number;
9
+ readonly scale?: number;
10
+ readonly alphaMin?: number;
11
+ readonly alphaRange?: number;
12
+ readonly decayMin?: number;
13
+ readonly decayRange?: number;
14
+ readonly verticalFade?: [number, number];
15
+ }
16
+
17
+ export class ShootingStarSystem {
18
+ readonly #interval: [number, number];
19
+ readonly #color: [number, number, number];
20
+ readonly #trailLength: number;
21
+ readonly #trailAlphaFactor: number;
22
+ readonly #speed: number;
23
+ readonly #scale: number;
24
+ readonly #alphaMin: number;
25
+ readonly #alphaRange: number;
26
+ readonly #decayMin: number;
27
+ readonly #decayRange: number;
28
+ readonly #verticalFade: [number, number] | null;
29
+ readonly #rng: () => number;
30
+ #cooldown: number;
31
+ #height: number = 0;
32
+ #stars: ShootingStar[] = [];
33
+
34
+ constructor(config: ShootingStarSystemConfig, rng: () => number) {
35
+ this.#interval = config.interval;
36
+ this.#color = config.color ?? [200, 230, 255];
37
+ this.#trailLength = config.trailLength ?? 18;
38
+ this.#trailAlphaFactor = config.trailAlphaFactor ?? 0.5;
39
+ this.#speed = config.speed ?? 1;
40
+ this.#scale = config.scale ?? 1;
41
+ this.#alphaMin = config.alphaMin ?? 0.7;
42
+ this.#alphaRange = config.alphaRange ?? 0.3;
43
+ this.#decayMin = config.decayMin ?? 0.008;
44
+ this.#decayRange = config.decayRange ?? 0.01;
45
+ this.#verticalFade = config.verticalFade ?? null;
46
+ this.#rng = rng;
47
+ this.#cooldown = this.#interval[0] + this.#rng() * (this.#interval[1] - this.#interval[0]);
48
+ }
49
+
50
+ tick(dt: number, width: number, height: number): void {
51
+ this.#height = height;
52
+ this.#cooldown -= dt;
53
+
54
+ if (this.#cooldown <= 0) {
55
+ this.#stars.push(this.#create(width, height));
56
+ this.#cooldown = this.#interval[0] + this.#rng() * (this.#interval[1] - this.#interval[0]);
57
+ }
58
+
59
+ let alive = 0;
60
+
61
+ for (let i = 0; i < this.#stars.length; i++) {
62
+ const star = this.#stars[i];
63
+
64
+ star.trail.push({x: star.x, y: star.y});
65
+
66
+ if (star.trail.length > this.#trailLength) {
67
+ star.trail.shift();
68
+ }
69
+
70
+ star.x += star.vx * this.#speed * dt;
71
+ star.y += star.vy * this.#speed * dt;
72
+ star.alpha -= star.decay * dt;
73
+
74
+ const inBounds = star.alpha > 0 && star.x > -50 && star.x < width + 50 && star.y < height + 50;
75
+ const fullyFaded = this.#verticalFade !== null && star.y / height >= this.#verticalFade[1];
76
+
77
+ if (inBounds && !fullyFaded) {
78
+ this.#stars[alive++] = star;
79
+ }
80
+ }
81
+
82
+ this.#stars.length = alive;
83
+ }
84
+
85
+ draw(ctx: CanvasRenderingContext2D): void {
86
+ const [cr, cg, cb] = this.#color;
87
+
88
+ ctx.globalCompositeOperation = 'lighter';
89
+
90
+ for (const star of this.#stars) {
91
+ let fadeFactor = 1;
92
+
93
+ if (this.#verticalFade && this.#height > 0) {
94
+ const [fadeStart, fadeEnd] = this.#verticalFade;
95
+ fadeFactor = 1 - Math.max(0, Math.min(1, (star.y / this.#height - fadeStart) / (fadeEnd - fadeStart)));
96
+ }
97
+
98
+ for (let t = 0; t < star.trail.length; t++) {
99
+ const progress = t / star.trail.length;
100
+ const trailAlpha = star.alpha * progress * this.#trailAlphaFactor * fadeFactor;
101
+ const trailSize = star.size * progress * this.#scale;
102
+
103
+ if (trailAlpha < 0.01) {
104
+ continue;
105
+ }
106
+
107
+ ctx.globalAlpha = trailAlpha;
108
+ ctx.beginPath();
109
+ ctx.arc(star.trail[t].x, star.trail[t].y, trailSize, 0, Math.PI * 2);
110
+ ctx.fillStyle = `rgb(${cr}, ${cg}, ${cb})`;
111
+ ctx.fill();
112
+ }
113
+
114
+ const alpha = star.alpha * fadeFactor;
115
+ const headSize = star.size * 2 * this.#scale;
116
+ const glow = ctx.createRadialGradient(star.x, star.y, 0, star.x, star.y, headSize);
117
+ glow.addColorStop(0, `rgba(${cr}, ${cg}, ${cb}, ${alpha})`);
118
+ glow.addColorStop(0.5, `rgba(${cr}, ${cg}, ${cb}, ${alpha * 0.3})`);
119
+ glow.addColorStop(1, `rgba(${cr}, ${cg}, ${cb}, 0)`);
120
+
121
+ ctx.globalAlpha = 1;
122
+ ctx.beginPath();
123
+ ctx.arc(star.x, star.y, headSize, 0, Math.PI * 2);
124
+ ctx.fillStyle = glow;
125
+ ctx.fill();
126
+ }
127
+
128
+ ctx.globalCompositeOperation = 'source-over';
129
+ ctx.globalAlpha = 1;
130
+ }
131
+
132
+ #create(width: number, height: number): ShootingStar {
133
+ const startX = this.#rng() * width * 0.8;
134
+ const startY = this.#rng() * height * 0.4;
135
+ const angle = 0.3 + this.#rng() * 0.5;
136
+ const speed = 8 + this.#rng() * 12;
137
+
138
+ return {
139
+ x: startX,
140
+ y: startY,
141
+ vx: Math.cos(angle) * speed * this.#scale,
142
+ vy: Math.sin(angle) * speed * this.#scale,
143
+ alpha: this.#alphaMin + this.#rng() * this.#alphaRange,
144
+ size: 1.5 + this.#rng() * 2,
145
+ decay: this.#decayMin + this.#rng() * this.#decayRange,
146
+ trail: []
147
+ };
148
+ }
149
+ }
@@ -0,0 +1,10 @@
1
+ export type ShootingStar = {
2
+ x: number;
3
+ y: number;
4
+ vx: number;
5
+ vy: number;
6
+ alpha: number;
7
+ size: number;
8
+ decay: number;
9
+ trail: {x: number; y: number}[];
10
+ };
@@ -0,0 +1,47 @@
1
+ import { LimitedFrameRateCanvas } from './canvas';
2
+ import type { SimulationLayer } from './layer';
3
+
4
+ export class SimulationCanvas extends LimitedFrameRateCanvas {
5
+ readonly #simulation: SimulationLayer;
6
+
7
+ constructor(canvas: HTMLCanvasElement, simulation: SimulationLayer, frameRate: number = 60, options: CanvasRenderingContext2DSettings = {colorSpace: 'display-p3'}) {
8
+ super(canvas, frameRate, options);
9
+ this.#simulation = simulation;
10
+
11
+ canvas.style.position = 'absolute';
12
+ canvas.style.top = '0';
13
+ canvas.style.left = '0';
14
+ canvas.style.height = '100%';
15
+ canvas.style.width = '100%';
16
+ }
17
+
18
+ start(): void {
19
+ this.#simulation.onMount(this.canvas);
20
+ super.start();
21
+ }
22
+
23
+ destroy(): void {
24
+ this.#simulation.onUnmount(this.canvas);
25
+ super.destroy();
26
+ }
27
+
28
+ draw(): void {
29
+ this.canvas.height = this.height;
30
+ this.canvas.width = this.width;
31
+
32
+ const ctx = this.context;
33
+ ctx.save();
34
+ this.#simulation.draw(ctx, this.width, this.height);
35
+ ctx.restore();
36
+ }
37
+
38
+ tick(): void {
39
+ const dt = (this.delta > 0 && this.delta < 200 ? this.delta / (1000 / 60) : 1) * this.speed * LimitedFrameRateCanvas.globalSpeed;
40
+ this.#simulation.tick(dt, this.width, this.height);
41
+ }
42
+
43
+ onResize(): void {
44
+ super.onResize();
45
+ this.#simulation.onResize(this.width, this.height);
46
+ }
47
+ }
@@ -1,3 +1,3 @@
1
- import { mulberry32 } from '@basmilius/utils';
1
+ import { type Mulberry32, mulberry32 } from '@basmilius/utils';
2
2
 
3
- export const MULBERRY = mulberry32(13);
3
+ export const MULBERRY: Mulberry32 = mulberry32(13);
package/src/snow/index.ts CHANGED
@@ -1,2 +1,3 @@
1
+ export { SnowLayer } from './layer';
1
2
  export { SnowSimulation } from './simulation';
2
3
  export type { SnowSimulationConfig } from './simulation';
@@ -0,0 +1,263 @@
1
+ import { parseColor } from '../color';
2
+ import { SimulationLayer } from '../layer';
3
+ import { MULBERRY } from './consts';
4
+ import type { SnowSimulationConfig } from './simulation';
5
+ import type { Snowflake } from './snowflake';
6
+
7
+ const SPRITE_SIZE = 64;
8
+ const SPRITE_CENTER = SPRITE_SIZE / 2;
9
+ const SPRITE_RADIUS = SPRITE_SIZE / 2;
10
+
11
+ export class SnowLayer extends SimulationLayer {
12
+ readonly #scale: number;
13
+ readonly #size: number;
14
+ readonly #speed: number;
15
+ readonly #baseOpacity: number;
16
+ #maxParticles: number;
17
+ #time: number = 0;
18
+ #ratio: number = 1;
19
+ #snowflakes: Snowflake[] = [];
20
+ #sprites: HTMLCanvasElement[] = [];
21
+ #height: number = 540;
22
+
23
+ constructor(config: SnowSimulationConfig = {}) {
24
+ super();
25
+
26
+ this.#scale = config.scale ?? 1;
27
+ this.#maxParticles = config.particles ?? 200;
28
+ this.#size = (config.size ?? 9) * this.#scale;
29
+ this.#speed = config.speed ?? 2;
30
+
31
+ const {r, g, b, a} = parseColor(config.fillStyle ?? 'rgb(255 255 255 / .75)');
32
+ this.#baseOpacity = a;
33
+
34
+ if (innerWidth < 991) {
35
+ this.#maxParticles = Math.floor(this.#maxParticles / 2);
36
+ }
37
+
38
+ this.#sprites = this.#createSprites(r, g, b);
39
+
40
+ for (let i = 0; i < this.#maxParticles; ++i) {
41
+ this.#snowflakes.push(this.#createSnowflake(true));
42
+ }
43
+ }
44
+
45
+ onResize(_width: number, height: number): void {
46
+ this.#height = height;
47
+ }
48
+
49
+ tick(dt: number, _width: number, height: number): void {
50
+ this.#height = height;
51
+
52
+ const speedFactor = height / (420 * this.#ratio) / this.#speed;
53
+
54
+ this.#time += 0.015 * speedFactor * dt;
55
+
56
+ const wind = Math.sin(this.#time * 0.7) * 0.5
57
+ + Math.sin(this.#time * 1.9 + 3) * 0.25
58
+ + Math.sin(this.#time * 4.3 + 1) * 0.1;
59
+
60
+ for (let index = 0; index < this.#snowflakes.length; index++) {
61
+ const snowflake = this.#snowflakes[index];
62
+
63
+ const swing = Math.sin(this.#time * snowflake.swingFrequency + snowflake.swingOffset) * snowflake.swingAmplitude;
64
+
65
+ snowflake.x += (swing + wind * snowflake.depth * 2) * dt / (4000 * speedFactor);
66
+ snowflake.y += (snowflake.fallSpeed * 2 + snowflake.depth + snowflake.radius * 0.15) * dt / (700 * speedFactor);
67
+
68
+ snowflake.rotation += snowflake.rotationSpeed * dt / speedFactor;
69
+
70
+ if (snowflake.x > 1.15 || snowflake.x < -0.15 || snowflake.y > 1.05) {
71
+ const recycled = this.#createSnowflake(false);
72
+
73
+ if (index % 3 > 0) {
74
+ recycled.x = MULBERRY.next();
75
+ recycled.y = -0.05 - MULBERRY.next() * 0.15;
76
+ } else if (wind > 0.2) {
77
+ recycled.x = -0.15;
78
+ recycled.y = MULBERRY.next() * 0.8;
79
+ } else if (wind < -0.2) {
80
+ recycled.x = 1.15;
81
+ recycled.y = MULBERRY.next() * 0.8;
82
+ } else {
83
+ recycled.x = MULBERRY.next();
84
+ recycled.y = -0.05 - MULBERRY.next() * 0.15;
85
+ }
86
+
87
+ this.#snowflakes[index] = recycled;
88
+ }
89
+ }
90
+ }
91
+
92
+ draw(ctx: CanvasRenderingContext2D, width: number, height: number): void {
93
+
94
+ for (const snowflake of this.#snowflakes) {
95
+ const px = snowflake.x * width;
96
+ const py = snowflake.y * height;
97
+ const displayRadius = snowflake.radius * snowflake.depth * this.#ratio;
98
+ const displaySize = displayRadius * 2;
99
+
100
+ if (displaySize < 0.5) {
101
+ continue;
102
+ }
103
+
104
+ ctx.globalAlpha = this.#baseOpacity * (0.15 + snowflake.depth * 0.85);
105
+
106
+ if (snowflake.spriteIndex === 3) {
107
+ ctx.save();
108
+ ctx.translate(px, py);
109
+ ctx.rotate(snowflake.rotation);
110
+ ctx.drawImage(
111
+ this.#sprites[snowflake.spriteIndex],
112
+ -displayRadius,
113
+ -displayRadius,
114
+ displaySize,
115
+ displaySize
116
+ );
117
+ ctx.restore();
118
+ } else {
119
+ ctx.drawImage(
120
+ this.#sprites[snowflake.spriteIndex],
121
+ px - displayRadius,
122
+ py - displayRadius,
123
+ displaySize,
124
+ displaySize
125
+ );
126
+ }
127
+ }
128
+
129
+ ctx.globalAlpha = 1;
130
+ }
131
+
132
+ #createSprites(r: number, g: number, b: number): HTMLCanvasElement[] {
133
+ const sprites: HTMLCanvasElement[] = [];
134
+
135
+ const gradientProfiles: [number, number][][] = [
136
+ [[0, 0.8], [0.3, 0.4], [0.7, 0.1], [1, 0]],
137
+ [[0, 1], [0.15, 0.7], [0.5, 0.2], [1, 0]],
138
+ [[0, 0.9], [0.25, 0.5], [0.5, 0.1], [1, 0]]
139
+ ];
140
+
141
+ for (const profile of gradientProfiles) {
142
+ const canvas = document.createElement('canvas');
143
+ canvas.width = SPRITE_SIZE;
144
+ canvas.height = SPRITE_SIZE;
145
+ const ctx = canvas.getContext('2d')!;
146
+
147
+ const gradient = ctx.createRadialGradient(
148
+ SPRITE_CENTER, SPRITE_CENTER, 0,
149
+ SPRITE_CENTER, SPRITE_CENTER, SPRITE_RADIUS
150
+ );
151
+
152
+ for (const [stop, alpha] of profile) {
153
+ gradient.addColorStop(stop, `rgba(${r}, ${g}, ${b}, ${alpha})`);
154
+ }
155
+
156
+ ctx.fillStyle = gradient;
157
+ ctx.beginPath();
158
+ ctx.arc(SPRITE_CENTER, SPRITE_CENTER, SPRITE_RADIUS, 0, Math.PI * 2);
159
+ ctx.fill();
160
+
161
+ sprites.push(canvas);
162
+ }
163
+
164
+ sprites.push(this.#createCrystalSprite(r, g, b));
165
+
166
+ return sprites;
167
+ }
168
+
169
+ #createCrystalSprite(r: number, g: number, b: number): HTMLCanvasElement {
170
+ const canvas = document.createElement('canvas');
171
+ canvas.width = SPRITE_SIZE;
172
+ canvas.height = SPRITE_SIZE;
173
+ const ctx = canvas.getContext('2d')!;
174
+
175
+ const glow = ctx.createRadialGradient(
176
+ SPRITE_CENTER, SPRITE_CENTER, 0,
177
+ SPRITE_CENTER, SPRITE_CENTER, SPRITE_RADIUS
178
+ );
179
+ glow.addColorStop(0, `rgba(${r}, ${g}, ${b}, 0.6)`);
180
+ glow.addColorStop(0.25, `rgba(${r}, ${g}, ${b}, 0.25)`);
181
+ glow.addColorStop(0.6, `rgba(${r}, ${g}, ${b}, 0.05)`);
182
+ glow.addColorStop(1, `rgba(${r}, ${g}, ${b}, 0)`);
183
+ ctx.fillStyle = glow;
184
+ ctx.beginPath();
185
+ ctx.arc(SPRITE_CENTER, SPRITE_CENTER, SPRITE_RADIUS, 0, Math.PI * 2);
186
+ ctx.fill();
187
+
188
+ ctx.strokeStyle = `rgba(${r}, ${g}, ${b}, 0.7)`;
189
+ ctx.lineWidth = 1.5;
190
+ ctx.lineCap = 'round';
191
+
192
+ const armLength = SPRITE_RADIUS * 0.75;
193
+
194
+ for (let arm = 0; arm < 6; arm++) {
195
+ const angle = (arm / 6) * Math.PI * 2 - Math.PI / 2;
196
+ const tipX = SPRITE_CENTER + Math.cos(angle) * armLength;
197
+ const tipY = SPRITE_CENTER + Math.sin(angle) * armLength;
198
+
199
+ ctx.beginPath();
200
+ ctx.moveTo(SPRITE_CENTER, SPRITE_CENTER);
201
+ ctx.lineTo(tipX, tipY);
202
+ ctx.stroke();
203
+
204
+ for (const position of [0.4, 0.65]) {
205
+ const branchX = SPRITE_CENTER + Math.cos(angle) * armLength * position;
206
+ const branchY = SPRITE_CENTER + Math.sin(angle) * armLength * position;
207
+ const branchLength = armLength * (0.4 - position * 0.3);
208
+
209
+ for (const side of [-1, 1]) {
210
+ const branchAngle = angle + side * Math.PI / 3;
211
+ ctx.beginPath();
212
+ ctx.moveTo(branchX, branchY);
213
+ ctx.lineTo(
214
+ branchX + Math.cos(branchAngle) * branchLength,
215
+ branchY + Math.sin(branchAngle) * branchLength
216
+ );
217
+ ctx.stroke();
218
+ }
219
+ }
220
+ }
221
+
222
+ const centerGlow = ctx.createRadialGradient(
223
+ SPRITE_CENTER, SPRITE_CENTER, 0,
224
+ SPRITE_CENTER, SPRITE_CENTER, SPRITE_RADIUS * 0.12
225
+ );
226
+ centerGlow.addColorStop(0, `rgba(${r}, ${g}, ${b}, 0.9)`);
227
+ centerGlow.addColorStop(1, `rgba(${r}, ${g}, ${b}, 0)`);
228
+ ctx.fillStyle = centerGlow;
229
+ ctx.beginPath();
230
+ ctx.arc(SPRITE_CENTER, SPRITE_CENTER, SPRITE_RADIUS * 0.12, 0, Math.PI * 2);
231
+ ctx.fill();
232
+
233
+ return canvas;
234
+ }
235
+
236
+ #createSnowflake(initialSpread: boolean): Snowflake {
237
+ const depth = 0.3 + MULBERRY.next() * 0.7;
238
+ const radius = MULBERRY.next() * this.#size + 2 * this.#scale;
239
+
240
+ let spriteIndex: number;
241
+ if (depth > 0.85 && radius > this.#size * 0.6 && MULBERRY.next() > 0.65) {
242
+ spriteIndex = 3;
243
+ } else if (depth < 0.45) {
244
+ spriteIndex = 2;
245
+ } else {
246
+ spriteIndex = MULBERRY.next() > 0.5 ? 0 : 1;
247
+ }
248
+
249
+ return {
250
+ x: MULBERRY.next(),
251
+ y: initialSpread ? MULBERRY.next() * 2 - 1 : -0.05 - MULBERRY.next() * 0.15,
252
+ depth,
253
+ radius,
254
+ rotation: MULBERRY.next() * Math.PI * 2,
255
+ rotationSpeed: (MULBERRY.next() - 0.5) * 0.03,
256
+ swingAmplitude: 0.3 + MULBERRY.next() * 0.7,
257
+ swingFrequency: 0.5 + MULBERRY.next() * 1.5,
258
+ swingOffset: MULBERRY.next() * Math.PI * 2,
259
+ fallSpeed: 0.5 + MULBERRY.next() * 0.5,
260
+ spriteIndex
261
+ };
262
+ }
263
+ }