Skip to content

Added rainbow colours (gradient) [updated] #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions visualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ let drawCurved = true;
let drawFilled = false;
//Whether to draw text the songText on top of the visualisation
let drawText = false;
//Rainbow gradients more your thing? You can enable this for full rainbow effect (this ignores "barColour")
let rainbowColours = false;

//Can't touch this
let audioContext;
Expand Down Expand Up @@ -93,14 +95,27 @@ function paint() {

if(!audioVisualizerInitialized)
return;

if (rainbowColors) {
var gradient = canvasContext.createLinearGradient(10, 0, canvasWidth, canvasHeight);
gradient.addColorStop(0, 'red');
gradient.addColorStop(1 / 6, 'orange');
gradient.addColorStop(2 / 6, 'yellow');
gradient.addColorStop(3 / 6, 'green');
gradient.addColorStop(4 / 6, 'blue');
gradient.addColorStop(5 / 6, 'indigo');
gradient.addColorStop(1, 'violet');
}

canvasContext.fillStyle = backgroundColour;
canvasContext.fillRect(0, 0, canvasWidth, canvasHeight);

let bins = audioAnalyserNode.frequencyBinCount;
let data = new Uint8Array(bins);
audioAnalyserNode.getByteFrequencyData(data);
canvasContext.fillStyle = barColour;

if (rainbowColors) { canvasContext.fillStyle = gradient; }
else { canvasContext.fillStyle = barColour; }

if (drawPitch)
updateBinsLog(logLookupTable, data);
Expand All @@ -112,7 +127,8 @@ function paint() {
paintSingleBin(i);
}
} else {
canvasContext.fillStyle = barColour;
if (rainbowColors) { canvasContext.fillStyle = gradient; }
else { canvasContext.fillStyle = barColour; }
canvasContext.beginPath();
canvasContext.moveTo(0, canvasHeight - getBinHeight(0));
let i;
Expand Down