-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
47 lines (36 loc) · 943 Bytes
/
sketch.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
const FIREWORK_RATIO = 0.00000005;
const BG_ALPHA = 60;
let fireworks = [];
let firework_rate;
function windowResized() {
resizeCanvas(innerWidth, innerHeight);
reset();
}
function onScreen(obj) {
if (obj instanceof Array) return obj.some((j) => onScreen(j));
obj = obj.pos ?? obj;
return obj.x > 0 && obj.x < width && obj.y > 0 && obj.y < height;
}
function reset() {
Firework.setVStartMax(height);
firework_rate = FIREWORK_RATIO * width * height;
}
function setup() {
createCanvas(innerWidth, innerHeight);
stroke("white");
strokeWeight(10);
background(0);
Particle.updateCallback = (particle) => {
stroke(particle.color);
point(particle.pos.x, particle.pos.y);
};
reset();
}
function draw() {
background(0, BG_ALPHA);
if (random() < firework_rate) fireworks.push(new Firework());
fireworks = fireworks.filter((f) => {
f.update();
return onScreen(f.particles) && f.alive;
});
}