@basmilius/sparkle 2.1.0 → 2.2.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/dist/index.d.mts +306 -459
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1106 -848
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -2
- package/src/aurora/index.ts +9 -3
- package/src/aurora/layer.ts +57 -29
- package/src/balloons/index.ts +9 -3
- package/src/balloons/layer.ts +50 -19
- package/src/bubbles/index.ts +9 -3
- package/src/bubbles/layer.ts +30 -17
- package/src/canvas.ts +12 -0
- package/src/color.ts +11 -2
- package/src/confetti/index.ts +15 -3
- package/src/confetti/layer.ts +8 -5
- package/src/confetti/particle.ts +12 -11
- package/src/donuts/consts.ts +2 -2
- package/src/donuts/index.ts +9 -3
- package/src/donuts/layer.ts +43 -12
- package/src/effect.ts +107 -0
- package/src/fade.ts +87 -0
- package/src/fireflies/index.ts +9 -3
- package/src/fireflies/layer.ts +26 -9
- package/src/fireflies/particle.ts +2 -2
- package/src/firepit/index.ts +9 -3
- package/src/firepit/layer.ts +26 -7
- package/src/fireworks/create-explosion.ts +237 -0
- package/src/fireworks/explosion.ts +1 -1
- package/src/fireworks/index.ts +15 -3
- package/src/fireworks/layer.ts +55 -304
- package/src/fireworks/spark.ts +2 -2
- package/src/fireworks/types.ts +2 -2
- package/src/glitter/index.ts +9 -4
- package/src/glitter/layer.ts +15 -7
- package/src/glitter/types.ts +10 -0
- package/src/index.ts +3 -4
- package/src/lanterns/index.ts +9 -4
- package/src/lanterns/layer.ts +22 -10
- package/src/lanterns/types.ts +8 -0
- package/src/layer.ts +13 -11
- package/src/leaves/index.ts +9 -4
- package/src/leaves/layer.ts +21 -14
- package/src/leaves/types.ts +9 -0
- package/src/lightning/index.ts +9 -4
- package/src/lightning/layer.ts +4 -4
- package/src/lightning/system.ts +3 -3
- package/src/lightning/types.ts +10 -2
- package/src/matrix/index.ts +9 -4
- package/src/matrix/layer.ts +15 -7
- package/src/matrix/types.ts +9 -0
- package/src/orbits/index.ts +9 -4
- package/src/orbits/layer.ts +51 -21
- package/src/orbits/types.ts +12 -1
- package/src/particles/index.ts +9 -3
- package/src/particles/layer.ts +55 -12
- package/src/petals/index.ts +9 -3
- package/src/petals/layer.ts +29 -13
- package/src/plasma/index.ts +9 -3
- package/src/plasma/layer.ts +21 -6
- package/src/rain/index.ts +9 -3
- package/src/rain/layer.ts +30 -8
- package/src/sandstorm/index.ts +9 -3
- package/src/sandstorm/layer.ts +26 -9
- package/src/scene.ts +201 -0
- package/src/shooting-stars/system.ts +26 -24
- package/src/shooting-stars/types.ts +2 -1
- package/src/simulation-canvas.ts +40 -4
- package/src/snow/index.ts +9 -3
- package/src/snow/layer.ts +24 -11
- package/src/sparklers/index.ts +13 -3
- package/src/sparklers/layer.ts +61 -15
- package/src/stars/index.ts +9 -3
- package/src/stars/layer.ts +28 -22
- package/src/streamers/index.ts +9 -3
- package/src/streamers/layer.ts +18 -6
- package/src/streamers/types.ts +1 -1
- package/src/waves/index.ts +9 -3
- package/src/waves/layer.ts +42 -45
- package/src/waves/types.ts +1 -0
- package/src/wormhole/index.ts +9 -3
- package/src/wormhole/layer.ts +22 -6
- package/src/aurora/simulation.ts +0 -19
- package/src/balloons/simulation.ts +0 -19
- package/src/bubbles/simulation.ts +0 -20
- package/src/confetti/simulation.ts +0 -27
- package/src/donuts/simulation.ts +0 -25
- package/src/fireflies/simulation.ts +0 -18
- package/src/firepit/simulation.ts +0 -17
- package/src/fireworks/simulation.ts +0 -18
- package/src/glitter/simulation.ts +0 -19
- package/src/lanterns/simulation.ts +0 -17
- package/src/layered.ts +0 -185
- package/src/leaves/simulation.ts +0 -18
- package/src/lightning/simulation.ts +0 -17
- package/src/matrix/simulation.ts +0 -18
- package/src/orbits/simulation.ts +0 -19
- package/src/particles/simulation.ts +0 -26
- package/src/petals/simulation.ts +0 -18
- package/src/plasma/simulation.ts +0 -17
- package/src/rain/simulation.ts +0 -21
- package/src/sandstorm/simulation.ts +0 -18
- package/src/snow/simulation.ts +0 -17
- package/src/sparklers/simulation.ts +0 -30
- package/src/stars/simulation.ts +0 -22
- package/src/streamers/simulation.ts +0 -16
- package/src/waves/simulation.ts +0 -18
- package/src/wormhole/simulation.ts +0 -17
package/src/waves/types.ts
CHANGED
package/src/wormhole/index.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Wormhole } from './layer';
|
|
2
|
+
import type { WormholeConfig } from './layer';
|
|
3
|
+
import type { Effect } from '../effect';
|
|
4
|
+
|
|
5
|
+
export function createWormhole(config?: WormholeConfig): Effect<WormholeConfig> {
|
|
6
|
+
return new Wormhole(config);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type { WormholeConfig };
|
|
4
10
|
export type { WormholeDirection, WormholeParticle } from './types';
|
package/src/wormhole/layer.ts
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
import { hexToRGB } from '@basmilius/utils';
|
|
2
|
-
import {
|
|
2
|
+
import { Effect } from '../effect';
|
|
3
3
|
import { MULBERRY } from './consts';
|
|
4
|
-
import type { WormholeSimulationConfig } from './simulation';
|
|
5
4
|
import type { WormholeDirection, WormholeParticle } from './types';
|
|
6
5
|
|
|
7
|
-
export
|
|
8
|
-
readonly
|
|
6
|
+
export interface WormholeConfig {
|
|
7
|
+
readonly count?: number;
|
|
8
|
+
readonly speed?: number;
|
|
9
|
+
readonly color?: string;
|
|
10
|
+
readonly direction?: WormholeDirection;
|
|
11
|
+
readonly scale?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class Wormhole extends Effect<WormholeConfig> {
|
|
15
|
+
#speed: number;
|
|
9
16
|
readonly #colorRGB: [number, number, number];
|
|
10
17
|
readonly #direction: WormholeDirection;
|
|
11
|
-
|
|
18
|
+
#scale: number;
|
|
12
19
|
#count: number;
|
|
13
20
|
#particles: WormholeParticle[] = [];
|
|
14
21
|
#width: number = 960;
|
|
15
22
|
#height: number = 540;
|
|
16
23
|
#initialized: boolean = false;
|
|
17
24
|
|
|
18
|
-
constructor(config:
|
|
25
|
+
constructor(config: WormholeConfig = {}) {
|
|
19
26
|
super();
|
|
20
27
|
|
|
21
28
|
let count = config.count ?? 200;
|
|
@@ -46,6 +53,15 @@ export class WormholeLayer extends SimulationLayer {
|
|
|
46
53
|
}
|
|
47
54
|
}
|
|
48
55
|
|
|
56
|
+
configure(config: Partial<WormholeConfig>): void {
|
|
57
|
+
if (config.speed !== undefined) {
|
|
58
|
+
this.#speed = config.speed;
|
|
59
|
+
}
|
|
60
|
+
if (config.scale !== undefined) {
|
|
61
|
+
this.#scale = config.scale;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
49
65
|
tick(dt: number, width: number, height: number): void {
|
|
50
66
|
this.#width = width;
|
|
51
67
|
this.#height = height;
|
package/src/aurora/simulation.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { SimulationCanvas } from '../simulation-canvas';
|
|
2
|
-
import { AuroraLayer } from './layer';
|
|
3
|
-
|
|
4
|
-
export interface AuroraSimulationConfig {
|
|
5
|
-
readonly bands?: number;
|
|
6
|
-
readonly colors?: string[];
|
|
7
|
-
readonly speed?: number;
|
|
8
|
-
readonly intensity?: number;
|
|
9
|
-
readonly waveAmplitude?: number;
|
|
10
|
-
readonly verticalPosition?: number;
|
|
11
|
-
readonly scale?: number;
|
|
12
|
-
readonly canvasOptions?: CanvasRenderingContext2DSettings;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class AuroraSimulation extends SimulationCanvas {
|
|
16
|
-
constructor(canvas: HTMLCanvasElement, config: AuroraSimulationConfig = {}) {
|
|
17
|
-
super(canvas, new AuroraLayer(config), 60, config.canvasOptions ?? {colorSpace: 'display-p3'});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { SimulationCanvas } from '../simulation-canvas';
|
|
2
|
-
import { BalloonLayer } from './layer';
|
|
3
|
-
|
|
4
|
-
export interface BalloonSimulationConfig {
|
|
5
|
-
readonly count?: number;
|
|
6
|
-
readonly colors?: string[];
|
|
7
|
-
readonly sizeRange?: [number, number];
|
|
8
|
-
readonly speed?: number;
|
|
9
|
-
readonly driftAmount?: number;
|
|
10
|
-
readonly stringLength?: number;
|
|
11
|
-
readonly scale?: number;
|
|
12
|
-
readonly canvasOptions?: CanvasRenderingContext2DSettings;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class BalloonSimulation extends SimulationCanvas {
|
|
16
|
-
constructor(canvas: HTMLCanvasElement, config: BalloonSimulationConfig = {}) {
|
|
17
|
-
super(canvas, new BalloonLayer(config), 60, config.canvasOptions ?? {colorSpace: 'display-p3'});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { SimulationCanvas } from '../simulation-canvas';
|
|
2
|
-
import { BubbleLayer } from './layer';
|
|
3
|
-
|
|
4
|
-
export interface BubbleSimulationConfig {
|
|
5
|
-
readonly count?: number;
|
|
6
|
-
readonly sizeRange?: [number, number];
|
|
7
|
-
readonly speed?: number;
|
|
8
|
-
readonly popOnClick?: boolean;
|
|
9
|
-
readonly popRadius?: number;
|
|
10
|
-
readonly colors?: string[];
|
|
11
|
-
readonly wobbleAmount?: number;
|
|
12
|
-
readonly scale?: number;
|
|
13
|
-
readonly canvasOptions?: CanvasRenderingContext2DSettings;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export class BubbleSimulation extends SimulationCanvas {
|
|
17
|
-
constructor(canvas: HTMLCanvasElement, config: BubbleSimulationConfig = {}) {
|
|
18
|
-
super(canvas, new BubbleLayer(config), 60, config.canvasOptions ?? {colorSpace: 'display-p3'});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { SimulationCanvas } from '../simulation-canvas';
|
|
2
|
-
import { ConfettiLayer } from './layer';
|
|
3
|
-
import type { Config } from './types';
|
|
4
|
-
|
|
5
|
-
export interface ConfettiSimulationConfig {
|
|
6
|
-
readonly scale?: number;
|
|
7
|
-
readonly canvasOptions?: CanvasRenderingContext2DSettings;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export class ConfettiSimulation extends SimulationCanvas {
|
|
11
|
-
readonly #layer: ConfettiLayer;
|
|
12
|
-
|
|
13
|
-
constructor(canvas: HTMLCanvasElement, config: ConfettiSimulationConfig = {}) {
|
|
14
|
-
const layer = new ConfettiLayer(config);
|
|
15
|
-
super(canvas, layer, 60, config.canvasOptions ?? {colorSpace: 'display-p3'});
|
|
16
|
-
this.#layer = layer;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
fire(config: Partial<Config>): void {
|
|
20
|
-
this.onResize();
|
|
21
|
-
this.#layer.fire(config);
|
|
22
|
-
|
|
23
|
-
if (!this.isTicking) {
|
|
24
|
-
this.start();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
package/src/donuts/simulation.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { SimulationCanvas } from '../simulation-canvas';
|
|
2
|
-
import { DonutLayer } from './layer';
|
|
3
|
-
|
|
4
|
-
export interface DonutSimulationConfig {
|
|
5
|
-
readonly background?: string;
|
|
6
|
-
readonly canvasOptions?: CanvasRenderingContext2DSettings;
|
|
7
|
-
readonly collisionPadding?: number;
|
|
8
|
-
readonly colors?: string[];
|
|
9
|
-
readonly count?: number;
|
|
10
|
-
readonly mouseAvoidance?: boolean;
|
|
11
|
-
readonly mouseAvoidanceRadius?: number;
|
|
12
|
-
readonly mouseAvoidanceStrength?: number;
|
|
13
|
-
readonly radiusRange?: [number, number];
|
|
14
|
-
readonly repulsionStrength?: number;
|
|
15
|
-
readonly rotationSpeedRange?: [number, number];
|
|
16
|
-
readonly scale?: number;
|
|
17
|
-
readonly speedRange?: [number, number];
|
|
18
|
-
readonly thickness?: number;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class DonutSimulation extends SimulationCanvas {
|
|
22
|
-
constructor(canvas: HTMLCanvasElement, config: DonutSimulationConfig = {}) {
|
|
23
|
-
super(canvas, new DonutLayer(config), 60, config.canvasOptions ?? {colorSpace: 'display-p3'});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { SimulationCanvas } from '../simulation-canvas';
|
|
2
|
-
import { FireflyLayer } from './layer';
|
|
3
|
-
|
|
4
|
-
export interface FireflySimulationConfig {
|
|
5
|
-
readonly count?: number;
|
|
6
|
-
readonly color?: string;
|
|
7
|
-
readonly size?: number;
|
|
8
|
-
readonly speed?: number;
|
|
9
|
-
readonly glowSpeed?: number;
|
|
10
|
-
readonly scale?: number;
|
|
11
|
-
readonly canvasOptions?: CanvasRenderingContext2DSettings;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class FireflySimulation extends SimulationCanvas {
|
|
15
|
-
constructor(canvas: HTMLCanvasElement, config: FireflySimulationConfig = {}) {
|
|
16
|
-
super(canvas, new FireflyLayer(config), 60, config.canvasOptions ?? {colorSpace: 'display-p3'});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { SimulationCanvas } from '../simulation-canvas';
|
|
2
|
-
import { FirepitLayer } from './layer';
|
|
3
|
-
|
|
4
|
-
export interface FirepitSimulationConfig {
|
|
5
|
-
readonly embers?: number;
|
|
6
|
-
readonly flameWidth?: number;
|
|
7
|
-
readonly flameHeight?: number;
|
|
8
|
-
readonly intensity?: number;
|
|
9
|
-
readonly scale?: number;
|
|
10
|
-
readonly canvasOptions?: CanvasRenderingContext2DSettings;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class FirepitSimulation extends SimulationCanvas {
|
|
14
|
-
constructor(canvas: HTMLCanvasElement, config: FirepitSimulationConfig = {}) {
|
|
15
|
-
super(canvas, new FirepitLayer(config), 60, config.canvasOptions ?? {colorSpace: 'display-p3'});
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { SimulationCanvas } from '../simulation-canvas';
|
|
2
|
-
import { FireworkLayer } from './layer';
|
|
3
|
-
import type { Point } from '../point';
|
|
4
|
-
import type { FireworkSimulationConfig, FireworkVariant } from './types';
|
|
5
|
-
|
|
6
|
-
export class FireworkSimulation extends SimulationCanvas {
|
|
7
|
-
readonly #layer: FireworkLayer;
|
|
8
|
-
|
|
9
|
-
constructor(canvas: HTMLCanvasElement, config: FireworkSimulationConfig = {}) {
|
|
10
|
-
const layer = new FireworkLayer(config);
|
|
11
|
-
super(canvas, layer, 60, config.canvasOptions ?? {colorSpace: 'display-p3'});
|
|
12
|
-
this.#layer = layer;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
fireExplosion(variant: FireworkVariant, position?: Point): void {
|
|
16
|
-
this.#layer.fireExplosion(variant, position);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { SimulationCanvas } from '../simulation-canvas';
|
|
2
|
-
import { GlitterLayer } from './layer';
|
|
3
|
-
|
|
4
|
-
export interface GlitterSimulationConfig {
|
|
5
|
-
readonly count?: number;
|
|
6
|
-
readonly colors?: string[];
|
|
7
|
-
readonly size?: number;
|
|
8
|
-
readonly speed?: number;
|
|
9
|
-
readonly groundLevel?: number;
|
|
10
|
-
readonly maxSettled?: number;
|
|
11
|
-
readonly scale?: number;
|
|
12
|
-
readonly canvasOptions?: CanvasRenderingContext2DSettings;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class GlitterSimulation extends SimulationCanvas {
|
|
16
|
-
constructor(canvas: HTMLCanvasElement, config: GlitterSimulationConfig = {}) {
|
|
17
|
-
super(canvas, new GlitterLayer(config), 60, config.canvasOptions ?? {colorSpace: 'display-p3'});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { SimulationCanvas } from '../simulation-canvas';
|
|
2
|
-
import { LanternLayer } from './layer';
|
|
3
|
-
|
|
4
|
-
export interface LanternSimulationConfig {
|
|
5
|
-
readonly count?: number;
|
|
6
|
-
readonly colors?: string[];
|
|
7
|
-
readonly size?: number;
|
|
8
|
-
readonly speed?: number;
|
|
9
|
-
readonly scale?: number;
|
|
10
|
-
readonly canvasOptions?: CanvasRenderingContext2DSettings;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class LanternSimulation extends SimulationCanvas {
|
|
14
|
-
constructor(canvas: HTMLCanvasElement, config: LanternSimulationConfig = {}) {
|
|
15
|
-
super(canvas, new LanternLayer(config), 60, config.canvasOptions ?? {colorSpace: 'display-p3'});
|
|
16
|
-
}
|
|
17
|
-
}
|
package/src/layered.ts
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { LimitedFrameRateCanvas } from './canvas';
|
|
2
|
-
import type { EdgeFade, EdgeFadeSide, SimulationLayer } from './layer';
|
|
3
|
-
|
|
4
|
-
function parseSide(side: EdgeFadeSide): [number, number] {
|
|
5
|
-
return typeof side === 'number' ? [0, side] : side;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function applyEdgeFade(ctx: CanvasRenderingContext2D, width: number, height: number, fade: EdgeFade): void {
|
|
10
|
-
ctx.globalCompositeOperation = 'destination-out';
|
|
11
|
-
|
|
12
|
-
if (fade.top !== undefined) {
|
|
13
|
-
const [near, far] = parseSide(fade.top);
|
|
14
|
-
const nearPx = near * height;
|
|
15
|
-
const farPx = far * height;
|
|
16
|
-
|
|
17
|
-
if (nearPx > 0) {
|
|
18
|
-
ctx.fillStyle = 'rgba(0,0,0,1)';
|
|
19
|
-
ctx.fillRect(0, 0, width, nearPx);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (farPx > nearPx) {
|
|
23
|
-
const gradient = ctx.createLinearGradient(0, nearPx, 0, farPx);
|
|
24
|
-
gradient.addColorStop(0, 'rgba(0,0,0,1)');
|
|
25
|
-
gradient.addColorStop(1, 'rgba(0,0,0,0)');
|
|
26
|
-
ctx.fillStyle = gradient;
|
|
27
|
-
ctx.fillRect(0, nearPx, width, farPx - nearPx);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (fade.bottom !== undefined) {
|
|
32
|
-
const [near, far] = parseSide(fade.bottom);
|
|
33
|
-
const nearPx = near * height;
|
|
34
|
-
const farPx = far * height;
|
|
35
|
-
|
|
36
|
-
if (nearPx > 0) {
|
|
37
|
-
ctx.fillStyle = 'rgba(0,0,0,1)';
|
|
38
|
-
ctx.fillRect(0, height - nearPx, width, nearPx);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (farPx > nearPx) {
|
|
42
|
-
const gradient = ctx.createLinearGradient(0, height - farPx, 0, height - nearPx);
|
|
43
|
-
gradient.addColorStop(0, 'rgba(0,0,0,0)');
|
|
44
|
-
gradient.addColorStop(1, 'rgba(0,0,0,1)');
|
|
45
|
-
ctx.fillStyle = gradient;
|
|
46
|
-
ctx.fillRect(0, height - farPx, width, farPx - nearPx);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (fade.left !== undefined) {
|
|
51
|
-
const [near, far] = parseSide(fade.left);
|
|
52
|
-
const nearPx = near * width;
|
|
53
|
-
const farPx = far * width;
|
|
54
|
-
|
|
55
|
-
if (nearPx > 0) {
|
|
56
|
-
ctx.fillStyle = 'rgba(0,0,0,1)';
|
|
57
|
-
ctx.fillRect(0, 0, nearPx, height);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (farPx > nearPx) {
|
|
61
|
-
const gradient = ctx.createLinearGradient(nearPx, 0, farPx, 0);
|
|
62
|
-
gradient.addColorStop(0, 'rgba(0,0,0,1)');
|
|
63
|
-
gradient.addColorStop(1, 'rgba(0,0,0,0)');
|
|
64
|
-
ctx.fillStyle = gradient;
|
|
65
|
-
ctx.fillRect(nearPx, 0, farPx - nearPx, height);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (fade.right !== undefined) {
|
|
70
|
-
const [near, far] = parseSide(fade.right);
|
|
71
|
-
const nearPx = near * width;
|
|
72
|
-
const farPx = far * width;
|
|
73
|
-
|
|
74
|
-
if (nearPx > 0) {
|
|
75
|
-
ctx.fillStyle = 'rgba(0,0,0,1)';
|
|
76
|
-
ctx.fillRect(width - nearPx, 0, nearPx, height);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (farPx > nearPx) {
|
|
80
|
-
const gradient = ctx.createLinearGradient(width - farPx, 0, width - nearPx, 0);
|
|
81
|
-
gradient.addColorStop(0, 'rgba(0,0,0,0)');
|
|
82
|
-
gradient.addColorStop(1, 'rgba(0,0,0,1)');
|
|
83
|
-
ctx.fillStyle = gradient;
|
|
84
|
-
ctx.fillRect(width - farPx, 0, farPx - nearPx, height);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
ctx.globalCompositeOperation = 'source-over';
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export class LayeredSimulation extends LimitedFrameRateCanvas {
|
|
92
|
-
readonly #layers: SimulationLayer[] = [];
|
|
93
|
-
readonly #contextOptions: CanvasRenderingContext2DSettings;
|
|
94
|
-
#offscreen: HTMLCanvasElement | null = null;
|
|
95
|
-
#offscreenCtx: CanvasRenderingContext2D | null = null;
|
|
96
|
-
|
|
97
|
-
constructor(canvas: HTMLCanvasElement, frameRate: number = 60, options: CanvasRenderingContext2DSettings = {colorSpace: 'display-p3'}) {
|
|
98
|
-
super(canvas, frameRate, options);
|
|
99
|
-
this.#contextOptions = options;
|
|
100
|
-
|
|
101
|
-
canvas.style.position = 'absolute';
|
|
102
|
-
canvas.style.top = '0';
|
|
103
|
-
canvas.style.left = '0';
|
|
104
|
-
canvas.style.height = '100%';
|
|
105
|
-
canvas.style.width = '100%';
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
add(layer: SimulationLayer): this {
|
|
109
|
-
this.#layers.push(layer);
|
|
110
|
-
|
|
111
|
-
if (this.isTicking) {
|
|
112
|
-
layer.onMount(this.canvas);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return this;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
start(): void {
|
|
119
|
-
for (const layer of this.#layers) {
|
|
120
|
-
layer.onMount(this.canvas);
|
|
121
|
-
}
|
|
122
|
-
super.start();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
destroy(): void {
|
|
126
|
-
for (const layer of this.#layers) {
|
|
127
|
-
layer.onUnmount(this.canvas);
|
|
128
|
-
}
|
|
129
|
-
super.destroy();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
draw(): void {
|
|
133
|
-
this.canvas.height = this.height;
|
|
134
|
-
this.canvas.width = this.width;
|
|
135
|
-
|
|
136
|
-
const ctx = this.context;
|
|
137
|
-
ctx.clearRect(0, 0, this.width, this.height);
|
|
138
|
-
|
|
139
|
-
for (const layer of this.#layers) {
|
|
140
|
-
if (layer.fade) {
|
|
141
|
-
const offCtx = this.#getOffscreenCtx(this.width, this.height);
|
|
142
|
-
offCtx.clearRect(0, 0, this.width, this.height);
|
|
143
|
-
layer.draw(offCtx, this.width, this.height);
|
|
144
|
-
applyEdgeFade(offCtx, this.width, this.height, layer.fade);
|
|
145
|
-
ctx.drawImage(this.#offscreen!, 0, 0);
|
|
146
|
-
} else {
|
|
147
|
-
ctx.save();
|
|
148
|
-
layer.draw(ctx, this.width, this.height);
|
|
149
|
-
ctx.restore();
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
tick(): void {
|
|
155
|
-
const dt = (this.delta > 0 && this.delta < 200 ? this.delta / (1000 / 60) : 1) * this.speed * LimitedFrameRateCanvas.globalSpeed;
|
|
156
|
-
|
|
157
|
-
for (const layer of this.#layers) {
|
|
158
|
-
layer.tick(dt, this.width, this.height);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
onResize(): void {
|
|
163
|
-
super.onResize();
|
|
164
|
-
|
|
165
|
-
if (this.#offscreen) {
|
|
166
|
-
this.#offscreen.width = this.width;
|
|
167
|
-
this.#offscreen.height = this.height;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
for (const layer of this.#layers) {
|
|
171
|
-
layer.onResize(this.width, this.height);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
#getOffscreenCtx(width: number, height: number): CanvasRenderingContext2D {
|
|
176
|
-
if (!this.#offscreen) {
|
|
177
|
-
this.#offscreen = document.createElement('canvas');
|
|
178
|
-
this.#offscreen.width = width;
|
|
179
|
-
this.#offscreen.height = height;
|
|
180
|
-
this.#offscreenCtx = this.#offscreen.getContext('2d', this.#contextOptions)!;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return this.#offscreenCtx!;
|
|
184
|
-
}
|
|
185
|
-
}
|
package/src/leaves/simulation.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { SimulationCanvas } from '../simulation-canvas';
|
|
2
|
-
import { LeafLayer } from './layer';
|
|
3
|
-
|
|
4
|
-
export interface LeafSimulationConfig {
|
|
5
|
-
readonly count?: number;
|
|
6
|
-
readonly colors?: string[];
|
|
7
|
-
readonly size?: number;
|
|
8
|
-
readonly speed?: number;
|
|
9
|
-
readonly wind?: number;
|
|
10
|
-
readonly scale?: number;
|
|
11
|
-
readonly canvasOptions?: CanvasRenderingContext2DSettings;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class LeafSimulation extends SimulationCanvas {
|
|
15
|
-
constructor(canvas: HTMLCanvasElement, config: LeafSimulationConfig = {}) {
|
|
16
|
-
super(canvas, new LeafLayer(config), 60, config.canvasOptions ?? {colorSpace: 'display-p3'});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { SimulationCanvas } from '../simulation-canvas';
|
|
2
|
-
import { LightningLayer } from './layer';
|
|
3
|
-
|
|
4
|
-
export interface LightningSimulationConfig {
|
|
5
|
-
readonly frequency?: number;
|
|
6
|
-
readonly color?: string;
|
|
7
|
-
readonly branches?: boolean;
|
|
8
|
-
readonly flash?: boolean;
|
|
9
|
-
readonly scale?: number;
|
|
10
|
-
readonly canvasOptions?: CanvasRenderingContext2DSettings;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class LightningSimulation extends SimulationCanvas {
|
|
14
|
-
constructor(canvas: HTMLCanvasElement, config: LightningSimulationConfig = {}) {
|
|
15
|
-
super(canvas, new LightningLayer(config), 60, config.canvasOptions ?? {colorSpace: 'display-p3'});
|
|
16
|
-
}
|
|
17
|
-
}
|
package/src/matrix/simulation.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { SimulationCanvas } from '../simulation-canvas';
|
|
2
|
-
import { MatrixLayer } from './layer';
|
|
3
|
-
|
|
4
|
-
export interface MatrixSimulationConfig {
|
|
5
|
-
readonly columns?: number;
|
|
6
|
-
readonly speed?: number;
|
|
7
|
-
readonly color?: string;
|
|
8
|
-
readonly fontSize?: number;
|
|
9
|
-
readonly trailLength?: number;
|
|
10
|
-
readonly scale?: number;
|
|
11
|
-
readonly canvasOptions?: CanvasRenderingContext2DSettings;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class MatrixSimulation extends SimulationCanvas {
|
|
15
|
-
constructor(canvas: HTMLCanvasElement, config: MatrixSimulationConfig = {}) {
|
|
16
|
-
super(canvas, new MatrixLayer(config), 60, config.canvasOptions ?? {colorSpace: 'display-p3'});
|
|
17
|
-
}
|
|
18
|
-
}
|
package/src/orbits/simulation.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { SimulationCanvas } from '../simulation-canvas';
|
|
2
|
-
import { OrbitLayer } from './layer';
|
|
3
|
-
|
|
4
|
-
export interface OrbitSimulationConfig {
|
|
5
|
-
readonly centers?: number;
|
|
6
|
-
readonly orbitersPerCenter?: number;
|
|
7
|
-
readonly speed?: number;
|
|
8
|
-
readonly colors?: string[];
|
|
9
|
-
readonly trailLength?: number;
|
|
10
|
-
readonly showCenters?: boolean;
|
|
11
|
-
readonly scale?: number;
|
|
12
|
-
readonly canvasOptions?: CanvasRenderingContext2DSettings;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class OrbitSimulation extends SimulationCanvas {
|
|
16
|
-
constructor(canvas: HTMLCanvasElement, config: OrbitSimulationConfig = {}) {
|
|
17
|
-
super(canvas, new OrbitLayer(config), 60, config.canvasOptions ?? {colorSpace: 'display-p3'});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { SimulationCanvas } from '../simulation-canvas';
|
|
2
|
-
import { ParticleLayer } from './layer';
|
|
3
|
-
|
|
4
|
-
export interface ParticleSimulationConfig {
|
|
5
|
-
readonly count?: number;
|
|
6
|
-
readonly color?: string;
|
|
7
|
-
readonly lineColor?: string;
|
|
8
|
-
readonly size?: [number, number];
|
|
9
|
-
readonly speed?: [number, number];
|
|
10
|
-
readonly connectionDistance?: number;
|
|
11
|
-
readonly lineWidth?: number;
|
|
12
|
-
readonly mouseMode?: import('./types').ParticleMouseMode;
|
|
13
|
-
readonly mouseRadius?: number;
|
|
14
|
-
readonly mouseStrength?: number;
|
|
15
|
-
readonly particleForces?: boolean;
|
|
16
|
-
readonly glow?: boolean;
|
|
17
|
-
readonly background?: string | null;
|
|
18
|
-
readonly scale?: number;
|
|
19
|
-
readonly canvasOptions?: CanvasRenderingContext2DSettings;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class ParticleSimulation extends SimulationCanvas {
|
|
23
|
-
constructor(canvas: HTMLCanvasElement, config: ParticleSimulationConfig = {}) {
|
|
24
|
-
super(canvas, new ParticleLayer(config), 60, config.canvasOptions ?? {colorSpace: 'display-p3'});
|
|
25
|
-
}
|
|
26
|
-
}
|
package/src/petals/simulation.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { SimulationCanvas } from '../simulation-canvas';
|
|
2
|
-
import { PetalLayer } from './layer';
|
|
3
|
-
|
|
4
|
-
export interface PetalSimulationConfig {
|
|
5
|
-
readonly count?: number;
|
|
6
|
-
readonly colors?: string[];
|
|
7
|
-
readonly size?: number;
|
|
8
|
-
readonly speed?: number;
|
|
9
|
-
readonly wind?: number;
|
|
10
|
-
readonly scale?: number;
|
|
11
|
-
readonly canvasOptions?: CanvasRenderingContext2DSettings;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class PetalSimulation extends SimulationCanvas {
|
|
15
|
-
constructor(canvas: HTMLCanvasElement, config: PetalSimulationConfig = {}) {
|
|
16
|
-
super(canvas, new PetalLayer(config), 60, config.canvasOptions ?? {colorSpace: 'display-p3'});
|
|
17
|
-
}
|
|
18
|
-
}
|
package/src/plasma/simulation.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { SimulationCanvas } from '../simulation-canvas';
|
|
2
|
-
import { PlasmaLayer } from './layer';
|
|
3
|
-
import type { PlasmaColor } from './types';
|
|
4
|
-
|
|
5
|
-
export interface PlasmaSimulationConfig {
|
|
6
|
-
readonly speed?: number;
|
|
7
|
-
readonly scale?: number;
|
|
8
|
-
readonly resolution?: number;
|
|
9
|
-
readonly palette?: PlasmaColor[];
|
|
10
|
-
readonly canvasOptions?: CanvasRenderingContext2DSettings;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class PlasmaSimulation extends SimulationCanvas {
|
|
14
|
-
constructor(canvas: HTMLCanvasElement, config: PlasmaSimulationConfig = {}) {
|
|
15
|
-
super(canvas, new PlasmaLayer(config), 60, config.canvasOptions ?? {colorSpace: 'display-p3'});
|
|
16
|
-
}
|
|
17
|
-
}
|
package/src/rain/simulation.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { SimulationCanvas } from '../simulation-canvas';
|
|
2
|
-
import { RainLayer } from './layer';
|
|
3
|
-
import type { RainVariant } from './types';
|
|
4
|
-
|
|
5
|
-
export interface RainSimulationConfig {
|
|
6
|
-
readonly variant?: RainVariant;
|
|
7
|
-
readonly drops?: number;
|
|
8
|
-
readonly wind?: number;
|
|
9
|
-
readonly speed?: number;
|
|
10
|
-
readonly splashes?: boolean;
|
|
11
|
-
readonly color?: string;
|
|
12
|
-
readonly groundLevel?: number;
|
|
13
|
-
readonly scale?: number;
|
|
14
|
-
readonly canvasOptions?: CanvasRenderingContext2DSettings;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class RainSimulation extends SimulationCanvas {
|
|
18
|
-
constructor(canvas: HTMLCanvasElement, config: RainSimulationConfig = {}) {
|
|
19
|
-
super(canvas, new RainLayer(config), 60, config.canvasOptions ?? {colorSpace: 'display-p3'});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { SimulationCanvas } from '../simulation-canvas';
|
|
2
|
-
import { SandstormLayer } from './layer';
|
|
3
|
-
|
|
4
|
-
export interface SandstormSimulationConfig {
|
|
5
|
-
readonly count?: number;
|
|
6
|
-
readonly wind?: number;
|
|
7
|
-
readonly turbulence?: number;
|
|
8
|
-
readonly color?: string;
|
|
9
|
-
readonly hazeOpacity?: number;
|
|
10
|
-
readonly scale?: number;
|
|
11
|
-
readonly canvasOptions?: CanvasRenderingContext2DSettings;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class SandstormSimulation extends SimulationCanvas {
|
|
15
|
-
constructor(canvas: HTMLCanvasElement, config: SandstormSimulationConfig = {}) {
|
|
16
|
-
super(canvas, new SandstormLayer(config), 60, config.canvasOptions ?? {colorSpace: 'display-p3'});
|
|
17
|
-
}
|
|
18
|
-
}
|
package/src/snow/simulation.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { SimulationCanvas } from '../simulation-canvas';
|
|
2
|
-
import { SnowLayer } from './layer';
|
|
3
|
-
|
|
4
|
-
export interface SnowSimulationConfig {
|
|
5
|
-
readonly fillStyle?: string;
|
|
6
|
-
readonly particles?: number;
|
|
7
|
-
readonly scale?: number;
|
|
8
|
-
readonly size?: number;
|
|
9
|
-
readonly speed?: number;
|
|
10
|
-
readonly canvasOptions?: CanvasRenderingContext2DSettings;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class SnowSimulation extends SimulationCanvas {
|
|
14
|
-
constructor(canvas: HTMLCanvasElement, config: SnowSimulationConfig = {}) {
|
|
15
|
-
super(canvas, new SnowLayer(config), 60, config.canvasOptions ?? {colorSpace: 'display-p3'});
|
|
16
|
-
}
|
|
17
|
-
}
|