Skip to content

Commit 622638f

Browse files
committed
Dynamic Analyser Gradient
Scale the colour gradient so that the analyser bars don’t go into the red as you scale the analyser.
1 parent 3d723f3 commit 622638f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

js/graph_spectrum.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ try {
219219
var x = 0;
220220

221221
var barGradient = canvasCtx.createLinearGradient(0,HEIGHT,0,0);
222-
barGradient.addColorStop(0, 'rgba(0,255,0,0.2)');
223-
barGradient.addColorStop(0.15, 'rgba(128,255,0,0.2)');
224-
barGradient.addColorStop(0.45, 'rgba(255,0,0,0.5)');
225-
barGradient.addColorStop(1, 'rgba(255,128,128,1.0)');
222+
barGradient.addColorStop(constrain(0/analyserZoomY,0,1), 'rgba(0,255,0,0.2)');
223+
barGradient.addColorStop(constrain(0.15/analyserZoomY,0,1), 'rgba(128,255,0,0.2)');
224+
barGradient.addColorStop(constrain(0.45/analyserZoomY,0,1), 'rgba(255,0,0,0.5)');
225+
barGradient.addColorStop(constrain(1/analyserZoomY, 0, 1), 'rgba(255,128,128,1.0)');
226226
canvasCtx.fillStyle = barGradient; //'rgba(0,255,0,0.3)'; //green
227227

228228
var fftScale = HEIGHT / (analyserZoomY*100);

0 commit comments

Comments
 (0)