-
Notifications
You must be signed in to change notification settings - Fork 1
/
fp.js
104 lines (77 loc) · 2.14 KB
/
fp.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* eslint-disable */
const colors = ['#1abc9c', '#2ecc71', '#3498db', '#9b59b6', '#34495e'];
const radiusScale = 40;
let offset = 1;
let initialArc = 0;
let amplitude;
let direction = 0.1;
function setup() {
setupVisualizer();
createCanvas(windowWidth, windowHeight);
noFill();
strokeWeight(3);
frameRate(60);
stroke(255, 204, 0, 25);
background(0, 0, 0);
}
function draw() {
setRandomStroke();
background(0, 0, 0, 10);
// var numRings = 5
const buckets = ['bass', 'lowMid', 'mid', 'highMid', 'treble'];
drawCircle(radiusScale * 0, buckets[0]);
drawCircle(radiusScale * 1, buckets[1]);
drawCircle(radiusScale * 2, buckets[2]);
drawCircle(radiusScale * 3, buckets[3]);
drawCircle(radiusScale * 4, buckets[4]);
drawCircle(radiusScale * 5, buckets[3]);
drawCircle(radiusScale * 6, buckets[2]);
drawCircle(radiusScale * 7, buckets[1]);
drawCircle(radiusScale * 8, buckets[0]);
if (Math.abs(offset) > 15) {
direction = -direction;
}
// offset += direction
initialArc += 0.2;
}
function mousePressed() {
stroke(255, 204, 0, 25);
ellipse(mouseX, mouseY, 25);
}
function randomColor() {
return _.sample(colors);
}
function drawCircle(radius, bucket) {
const numPoints = radius / 8;
fft.analyze();
const arc = 360 / numPoints;
for (let i = 0; i < numPoints; i++) {
const angle = ((arc * i + initialArc) * Math.PI) / 180;
const xCoordinate =
windowWidth / 2 + (radius + offset * radius) * Math.cos(angle);
const yCoordinate =
windowHeight / 2 + (radius + offset * radius) * Math.sin(angle);
ellipse(xCoordinate, yCoordinate, Math.pow(fft.getEnergy(bucket), 2) / 100);
}
}
function preload() {
mySound = loadSound('/quantic.mp3');
}
function setRandomStroke() {
r = random(127, 255);
g = random(127, 255);
b = random(127, 255);
stroke(r, g, b, 50);
}
function setupVisualizer() {
mySound.setVolume(0.1);
mySound.jump(random(0, mySound.duration()));
fft = new p5.FFT();
fft.setInput(mySound);
amplitude = new p5.Amplitude();
}
window.onload = function () {
document.getElementById('offset').onchange = function (e) {
offset = e.target.value;
};
};