forked from ja-k-e/noise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
72 lines (58 loc) · 1.56 KB
/
app.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
import Particles from "./Particles.js";
import Sound from "./Sound.js";
const canvas = document.querySelector("canvas");
canvas.addEventListener("dragstart", (e) => e.preventDefault());
function preventPullToRefresh(element) {
var prevent = false;
element.addEventListener("touchstart", function (e) {
if (e.touches.length !== 1) {
return;
}
var scrollY =
window.pageYOffset ||
document.body.scrollTop ||
document.documentElement.scrollTop;
prevent = scrollY === 0;
});
element.addEventListener("touchmove", function (e) {
if (prevent) {
prevent = false;
e.preventDefault();
}
});
}
preventPullToRefresh(canvas);
const particles = new Particles(canvas);
let x = 0;
let y = 0;
let i = 0;
let sound;
document.body.addEventListener("click", onCanvasTap);
function onCanvasTap(event) {
if (!sound) {
document.querySelector("h1").remove();
document.body.style.cursor = "crosshair";
sound = new Sound();
tick();
document.body.addEventListener("touchmove", (e) => {
x = e.touches[0].clientX / window.innerWidth;
y = e.touches[0].clientY / window.innerHeight;
});
document.body.addEventListener("mousemove", (e) => {
x = e.clientX / window.innerWidth;
y = e.clientY / window.innerHeight;
});
}
x = event.clientX / window.innerWidth;
y = event.clientY / window.innerHeight;
}
function tick() {
requestAnimationFrame(tick);
sound.tick(x, y);
particles.drawParticles(
x * canvas.width,
y * canvas.height,
(1 - y) * 7.75 + 0.25
);
i++;
}