app.js
984 Bytes
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
import { WaveGroup } from "./wavegroup.js";
class App{
constructor(){
this.canvas = document.createElement('canvas');
this.ctx = this.canvas.getContext('2d');
document.body.appendChild(this.canvas);
this.waveGroup = new WaveGroup();
window.addEventListener('resize', this.resize.bind(this), false);
this.resize();
requestAnimationFrame(this.animate.bind(this));
}
resize() {
this.stageWidth = document.body.clientWidth;
this.stageHeight = document.body.clientHeight;
this.canvas.width = this.stageWidth * 2;
this.canvas.height = this.stageHeight * 2;
this.ctx.scale(2,2);
this.waveGroup.resize(this.stageWidth,this.stageHeight);
}
animate(t){
this.ctx.clearRect(0,0,this.stageWidth,this.stageHeight);
this.waveGroup.draw(this.ctx);
requestAnimationFrame(this.animate.bind(this));
}
}
window.onload = () =>{
new App();
}