-
Notifications
You must be signed in to change notification settings - Fork 75
/
init.js
92 lines (79 loc) · 1.91 KB
/
init.js
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
import ParticleSystem, {
Alpha,
Body,
Color,
CrossZone,
Emitter,
Force,
Life,
Mass,
RadialVelocity,
Radius,
Rate,
Scale,
ScreenZone,
Span,
SpriteRenderer,
Vector3D,
} from 'three-nebula';
import dot from '../../../assets/dot.png';
let THREE;
const createSprite = () => {
var map = new THREE.TextureLoader().load(dot);
var material = new THREE.SpriteMaterial({
map: map,
color: 0xff0000,
blending: THREE.AdditiveBlending,
fog: true,
});
return new THREE.Sprite(material);
};
const createEmitter = ({ colorA, colorB, camera, renderer }) => {
const emitter = new Emitter();
return emitter
.setRate(new Rate(new Span(5, 7), new Span(0.01, 0.02)))
.setInitializers([
new Mass(1),
new Life(2),
new Body(createSprite()),
new Radius(80),
new RadialVelocity(200, new Vector3D(0, 0, -1), 0),
])
.setBehaviours([
new Alpha(1, 0),
new Color(colorA, colorB),
new Scale(1, 0.5),
new CrossZone(new ScreenZone(camera, renderer), 'dead'),
new Force(0, 0, -20),
])
.emit();
};
const animateEmitters = (a, b, tha = 0, radius = 70) => {
tha += 0.13;
a.position.x = radius * Math.cos(tha);
a.position.y = radius * Math.sin(tha);
b.position.x = radius * Math.cos(tha + Math.PI / 2);
b.position.y = radius * Math.sin(tha + Math.PI / 2);
requestAnimationFrame(() => animateEmitters(a, b, tha, radius));
};
export default async (three, { scene, camera, renderer }) => {
THREE = three;
const system = new ParticleSystem();
const emitterA = createEmitter({
colorA: '#4F1500',
colorB: '#0029FF',
camera,
renderer,
});
const emitterB = createEmitter({
colorA: '#004CFE',
colorB: '#6600FF',
camera,
renderer,
});
animateEmitters(emitterA, emitterB);
return system
.addEmitter(emitterA)
.addEmitter(emitterB)
.addRenderer(new SpriteRenderer(scene, THREE));
};