Skip to content

Commit 38d0dbb

Browse files
committed
feat: Add HexagonWave component, remove WhirlpoolGalaxy, and expand stories for NeonRails and StartTrail with new configurations and a particle force property.
1 parent ffb692b commit 38d0dbb

11 files changed

Lines changed: 917 additions & 306 deletions

src/BeautifulBackground.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export abstract class BeautifulBackground extends LitElement {
1111
public width: number = 0;
1212
public height: number = 0;
1313
public animationFrameId: number | null = null;
14+
1415
@property({ type: Number, attribute: "trail-opacity" })
1516
public trailOpacity: number = 0.1;
1617

@@ -23,6 +24,14 @@ export abstract class BeautifulBackground extends LitElement {
2324
this.debouncedResize = debounce(this.resizeCanvas.bind(this), 100);
2425
}
2526

27+
protected handleVisibilityChange = () => {
28+
if (document.visibilityState === "hidden") {
29+
this.stopAnimation();
30+
} else {
31+
this.startAnimation();
32+
}
33+
};
34+
2635
protected firstUpdated() {
2736
if (!this.shadowRoot) {
2837
this.attachShadow({ mode: "open" });
@@ -34,14 +43,20 @@ export abstract class BeautifulBackground extends LitElement {
3443
this.startAnimation();
3544

3645
window.addEventListener("resize", this.debouncedResize);
46+
document.addEventListener(
47+
"visibilitychange",
48+
this.handleVisibilityChange,
49+
);
3750
}
3851

3952
disconnectedCallback() {
4053
super.disconnectedCallback();
4154
window.removeEventListener("resize", this.debouncedResize);
42-
if (this.animationFrameId !== null) {
43-
cancelAnimationFrame(this.animationFrameId);
44-
}
55+
document.removeEventListener(
56+
"visibilitychange",
57+
this.handleVisibilityChange,
58+
);
59+
this.stopAnimation();
4560
}
4661

4762
protected resizeCanvas(): void {
@@ -68,6 +83,8 @@ export abstract class BeautifulBackground extends LitElement {
6883
}
6984

7085
protected startAnimation() {
86+
if (this.animationFrameId !== null) return;
87+
7188
let lastTime = performance.now();
7289
const animate = (now: number) => {
7390
const deltaTime = (now - lastTime) / 1000;
@@ -78,6 +95,13 @@ export abstract class BeautifulBackground extends LitElement {
7895
this.animationFrameId = requestAnimationFrame(animate);
7996
}
8097

98+
protected stopAnimation() {
99+
if (this.animationFrameId !== null) {
100+
cancelAnimationFrame(this.animationFrameId);
101+
this.animationFrameId = null;
102+
}
103+
}
104+
81105
protected abstract loop(deltaTime: number): void;
82106

83107
render() {

src/stories/DigitalRain.stories.ts

Lines changed: 86 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,18 @@ type Story = StoryObj;
7171

7272
export const Default: Story = {
7373
args: {
74-
backgroundColor: "#000",
74+
characters: "アイウエオカキクケコ",
75+
fontColorHueStart: 120,
76+
fontColorHueEnd: 140,
77+
fontColorSaturationStart: 80,
78+
fontColorSaturationEnd: 100,
79+
fontColorLightnessStart: 40,
80+
fontColorLightnessEnd: 60,
81+
backgroundColor: "#000000",
82+
speed: 8,
83+
fontSize: 20,
84+
randomness: 0.95,
85+
trailOpacity: 0.08,
7586
},
7687
};
7788

@@ -90,9 +101,79 @@ export const PurpleRain: Story = {
90101
characters: "|",
91102
randomness: 0.98,
92103
fontSize: 12,
93-
fontColorHueStart: 267,
94-
fontColorHueEnd: 278,
95-
fontColorSaturationStart: 100,
96-
speed: 30,
104+
fontColorHueStart: 261,
105+
fontColorHueEnd: 289,
106+
fontColorSaturationStart: 87,
107+
speed: 5.4,
108+
fontColorLightnessStart: 43,
109+
fontColorLightnessEnd: 55,
110+
},
111+
};
112+
113+
export const NeonBlue: Story = {
114+
args: {
115+
characters: "ABCDEF0123456789",
116+
fontColorHueStart: 180,
117+
fontColorHueEnd: 210,
118+
fontColorSaturationStart: 90,
119+
fontColorSaturationEnd: 100,
120+
fontColorLightnessStart: 60,
121+
fontColorLightnessEnd: 70,
122+
backgroundColor: "#001122",
123+
speed: 6,
124+
fontSize: 18,
125+
randomness: 0.9,
126+
trailOpacity: 0.12,
127+
},
128+
};
129+
130+
export const OrangeFire: Story = {
131+
args: {
132+
characters: "▲◆●★",
133+
fontColorHueStart: 30,
134+
fontColorHueEnd: 45,
135+
fontColorSaturationStart: 80,
136+
fontColorSaturationEnd: 100,
137+
fontColorLightnessStart: 50,
138+
fontColorLightnessEnd: 60,
139+
backgroundColor: "#220000",
140+
speed: 7,
141+
fontSize: 22,
142+
randomness: 0.92,
143+
trailOpacity: 0.15,
144+
},
145+
};
146+
147+
export const GhostWhite: Story = {
148+
args: {
149+
characters: "░▒▓■□▲▼",
150+
fontColorHueStart: 0,
151+
fontColorHueEnd: 0,
152+
fontColorSaturationStart: 0,
153+
fontColorSaturationEnd: 0,
154+
fontColorLightnessStart: 80,
155+
fontColorLightnessEnd: 100,
156+
backgroundColor: "#111111",
157+
speed: 4,
158+
fontSize: 16,
159+
randomness: 0.98,
160+
trailOpacity: 0.05,
161+
},
162+
};
163+
164+
export const RainbowChaos: Story = {
165+
args: {
166+
characters: "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
167+
fontColorHueStart: 0,
168+
fontColorHueEnd: 360,
169+
fontColorSaturationStart: 70,
170+
fontColorSaturationEnd: 100,
171+
fontColorLightnessStart: 40,
172+
fontColorLightnessEnd: 80,
173+
backgroundColor: "#000000",
174+
speed: 9,
175+
fontSize: 14,
176+
randomness: 0.99,
177+
trailOpacity: 0.09,
97178
},
98179
};

0 commit comments

Comments
 (0)