-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
86 lines (68 loc) · 2.24 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
function setup() {
createCanvas(550, 550, WEBGL);
angleMode(DEGREES);
colorMode(RGB, 1);
frameRate(0);
}
function paintCircle(dataArray, r, iter){
const dir = [-1, 1];
for (let i = 0; i < MAX_FREQ_BUFFER; i+=DETAIL){
let angle = (i/MAX_FREQ_BUFFER)*180;
let index = i;
const x = r*cos(angle);
const y = -dataArray[index];
const z = r*sin(angle);
fill(i/MAX_FREQ_BUFFER, (MAX_FREQ_BUFFER-i)/MAX_FREQ_BUFFER, (MAX_FREQ_BUFFER-i)/MAX_FREQ_BUFFER, (HISTORY_COUNT-iter)/HISTORY_COUNT);
push();
translate(x, y, z);
box(5, y, 5);
pop();
}
for (let i = 0; i <= MAX_FREQ_BUFFER; i+=DETAIL){
let angle = -1*(i/MAX_FREQ_BUFFER)*180;
let index = i;
const x = r*cos(angle);
const y = -dataArray[index];
const z = r*sin(angle);
fill(i/MAX_FREQ_BUFFER, (MAX_FREQ_BUFFER-i)/MAX_FREQ_BUFFER, (MAX_FREQ_BUFFER-i)/MAX_FREQ_BUFFER, (HISTORY_COUNT-iter)/HISTORY_COUNT);
push();
translate(x, y, z);
box(5, y, 5);
pop();
}
}
function paintLinear(dataArray, r, iter){
// beginShape(LINES);
for (let i = 0; i < MAX_FREQ_BUFFER; i+=DETAIL){
const x = -1000 + 2000*(i/MAX_FREQ_BUFFER);
const y = -dataArray[i];
const z = 1000-r;
fill(i/MAX_FREQ_BUFFER, (MAX_FREQ_BUFFER-i)/MAX_FREQ_BUFFER, (MAX_FREQ_BUFFER-i)/MAX_FREQ_BUFFER, (HISTORY_COUNT-iter)/HISTORY_COUNT);
push();
translate(x, y, z);
box(10, y, 10);
// vertex(x, y, z);
pop();
}
// endShape();
}
function draw() {
if (STARTED === true){
background(0);
orbitControl();
noStroke();
translate(0, 100, 0);
const myDataArray = normalizer.getData();
history.add(myDataArray);
const n = history.history.length;
for (let i = 0; i < n; i++){
push();
if (MODE === 'CIRCLE'){
paintCircle(history.history[i], DISTANCE*(i+1), i);
}else if(MODE == 'LINEAR'){
paintLinear(history.history[i], DISTANCE*(i+1), i);
}
pop();
}
}
}