From b4ca1320b85f5320052a5c0e7a6f138a037ca096 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Tue, 1 Jun 2021 16:37:17 +0200 Subject: [PATCH] Attempt to impose limits --- voicegardens/static/voicegardens.js | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/voicegardens/static/voicegardens.js b/voicegardens/static/voicegardens.js index d920fca..b48e832 100644 --- a/voicegardens/static/voicegardens.js +++ b/voicegardens/static/voicegardens.js @@ -10,6 +10,9 @@ var _canvas; // Offline recording duration var offlineRecordingDuration = 3000; +// Offline limits for hardware consierations +var offlineLimits = 6; + // URL which exposes the archive saving API end-point var archiveUrl = window.location + "add-to-archive"; var archiveListingUrl = window.location + "archive"; @@ -80,6 +83,22 @@ function stop() { } } +function gardenOfflineLimits() { + /** + * Ensure shapes stay within limits + **/ + if (shapes.length < offlineLimits) return; + + for (let i = 0; i < shapes.length; i++) { + let shape = shapes[i]; + shape.hide(); + } + + while (shapes.length > 0) { + shapes.pop(); + } +} + function sendToArchive() { /** * Send the sound to the back-end for archiving. @@ -286,6 +305,9 @@ class GeneratedShape { this.nextTick = random(1000, 9000); this.tickTimer = 0; + // Should remain hidden + this.hidden = false; + this.initialise(); } @@ -355,10 +377,26 @@ class GeneratedShape { } } + hide() { + /** + * Hide the shape + **/ + if (!this.hidden) { + this.hidden = true; + } + + while (this.colour._getAlpha() > 0) { + let currentAlpha = this.colour._getAlpha(); + this.colour.setAlpha(currentAlpha - random(0, 3)); + } + } + docolour() { /** * Draw colour and fade-in shape. **/ + if (this.hidden === true) return; + if (this.opacity != 256) { if (this.opacity < 256) { // shape should fade in, so increment alpha value @@ -552,6 +590,7 @@ function draw() { let amp = sound.getPeaks(1)[0] * 100; let dur = sound.duration(); let shape = new GeneratedShape(sound, amp, dur); + gardenOfflineLimits(); shape.sound(); shapes.push(shape); sendToArchive();