Browse Source

Attempt to impose limits

offline
decentral1se 3 years ago
parent
commit
b4ca1320b8
No known key found for this signature in database GPG Key ID: 92DAD76BD9567B8A
  1. 39
      voicegardens/static/voicegardens.js

39
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();

Loading…
Cancel
Save