-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
53 lines (44 loc) · 1.17 KB
/
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
48
49
50
51
52
53
//global for the controls and input
var controls = null;
//store visualisations in a container
var vis = null;
//variable for the p5 sound object
var sound = null;
//variable for p5 fast fourier transform
var fourier;
function preload() {
sound = loadSound('assets/sound1.mp3');
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(0);
controls = new ControlsAndInput();
//instantiate the fft object
fourier = new p5.FFT();
//create a new visualisation container and add visualisations
vis = new Visualisations();
vis.add(new Spectrum());
vis.add(new WavePattern());
vis.add(new Needles());
}
function draw() {
background(0);
//draw the selected visualisation
vis.selectedVisual.draw();
//draw the controls on top.
controls.draw();
}
function mouseClicked() {
controls.mousePressed();
}
function keyPressed() {
controls.keyPressed(keyCode);
}
//when the window has been resized. Resize canvas to fit
//if the visualisation needs to be resized call its onResize method
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
if (vis.selectedVisual.hasOwnProperty('onResize')) {
vis.selectedVisual.onResize();
}
}