-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpace.tsx
108 lines (96 loc) · 2.24 KB
/
Space.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { useEffect, useMemo, useState } from 'react';
import { atom, useAtom } from 'jotai';
import Particles, { initParticlesEngine } from '@tsparticles/react';
import { loadFull } from 'tsparticles';
import { loadEmittersPlugin } from '@tsparticles/plugin-emitters';
import { loadEmittersShapeSquare } from '@tsparticles/plugin-emitters-shape-square';
import { loadLifeUpdater } from '@tsparticles/updater-life';
import type { ISourceOptions } from '@tsparticles/engine';
import styles from './space.module.css';
export const shipSpeed = atom<number>(15);
const Space = () => {
const [init, setInit] = useState(false);
useEffect(() => {
initParticlesEngine(async (engine) => {
await loadFull(engine, false);
await loadEmittersShapeSquare(engine, false);
await loadEmittersPlugin(engine, false);
await loadLifeUpdater(engine, false);
}).then(() => {
setInit(true);
});
}, []);
const [speed] = useAtom(shipSpeed);
const options: ISourceOptions = useMemo(
() => ({
background: {
color: '#010101',
},
particles: {
number: {
value: 120,
},
color: {
value: '#ffffff',
},
life: {
count: 1,
duration: {
value: 6,
},
},
shape: {
type: 'circle',
},
opacity: {
value: 1,
},
size: {
value: 3,
},
move: {
enable: true,
speed: speed,
decay: 0.01,
direction: 'outside',
straight: true,
outModes: 'destroy',
trail: {
enable: true,
length: 12,
fill: {
color: '#000000',
},
},
},
},
emitters: [
{
position: {
x: 50,
y: 45,
},
size: {
width: 96,
height: 36,
},
rate: {
quantity: 10,
delay: 0.1,
},
},
],
}),
[speed]
);
if (init) {
return (
<Particles
id="space"
options={options}
/>
);
}
return <div className={styles.root} />;
};
export default Space;