-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·61 lines (47 loc) · 1.68 KB
/
Copy pathscript.js
File metadata and controls
executable file
·61 lines (47 loc) · 1.68 KB
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
import { MASS_PRESETS } from "./src/mass-presets.js";
import { MorphingMassController } from "./src/morphing-mass-controller.js";
const container = document.querySelector("#mass-canvas");
const cycleVariantButton = document.querySelector("#cycle-variant");
const energizeMassButton = document.querySelector("#energize-mass");
const presetName = document.querySelector("#preset-name");
let presetIndex = 0;
const controller = new MorphingMassController(container, {
preset: MASS_PRESETS[presetIndex]
});
function updatePresetLabel() {
presetName.textContent = MASS_PRESETS[presetIndex].name;
}
function applyPreset(index) {
presetIndex = (index + MASS_PRESETS.length) % MASS_PRESETS.length;
controller.setPreset(MASS_PRESETS[presetIndex]);
updatePresetLabel();
}
updatePresetLabel();
cycleVariantButton.addEventListener("click", () => {
applyPreset(presetIndex + 1);
controller.setActive(true);
});
energizeMassButton.addEventListener("click", () => {
controller.setActive(true);
controller.setEnergy(1);
window.setTimeout(() => controller.setEnergy(0.18), 420);
});
window.addEventListener("pointermove", (event) => {
controller.setPointer(event.clientX, event.clientY);
});
window.addEventListener("pointerdown", () => {
controller.setActive(true);
controller.setEnergy(0.9);
});
window.addEventListener("pointerup", () => {
controller.setEnergy(0.3);
});
window.addEventListener("pointerleave", () => {
controller.setActive(false);
controller.setEnergy(0.18);
});
window.addEventListener("focus", () => controller.setActive(true));
window.addEventListener("blur", () => controller.setActive(false));
window.addEventListener("beforeunload", () => {
controller.destroy();
});