forked from Luich2012/fftjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
64 lines (53 loc) · 1.64 KB
/
demo.html
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
<!doctype html>
<html>
<head>
<title>fftjs demo</title>
<script src="//cdnjs.cloudflare.com/ajax/libs/processing.js/1.4.1/processing-api.min.js"></script>
<script src="/fft.min.js"></script>
<style>
html,
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<canvas id="sketch"></canvas>
<script id="script">
// init fftjs
var fftjs = new FFTJS();
// 64 samples
fftjs.init(128);
// declare globals for processing
var width = window.innerWidth;
var height = window.innerHeight;
function drawerSketch(processing) {
// set size
processing.size(width, height);
processing.setup = function() {
processing.colorMode(processing.HSB, 360, 100, 100);
processing.noStroke();
};
// draw loop (runs each frame)
processing.draw = function() {
processing.background(0);
var fft = fftjs.fft();
var bands = fft.length;
bandWidth = width / bands;
for (var band in fft) {
var mappedHue = processing.map(fft[band], 0, 255, 180, 360);
processing.fill(mappedHue, 100, 100);
var bandHeight = processing.map(fft[band], 0, 256, 0, height);
processing.rect(band * bandWidth, height - bandHeight, bandWidth, bandHeight);
}
};
}
// attach the sketch function to the canvas
var processingInstance = new Processing(document.getElementById('sketch'), drawerSketch);
console.log(processingInstance);
</script>
</body>
</html>