xxxxxxxxxx
/**
* Radio Pick Active Sketch (v1.0.2)
* GoToLoop (2020-Mar-22)
*
* Discourse.Processing.org/t/instance-mode-calling-other-sketches/18893/2
*
* Glitch.com/~radio-pick-active-sketch
* Glitch.com/edit/#!/radio-pick-active-sketch?path=sketch.js
*
* OpenProcessing.org/sketch/861749
*/
"use strict";
const SKETCH = 'sketch ';
let activeSketch;
function setup() {
noCanvas();
print(sketches);
const radio = createRadio().changed(runPickedSketch);
for (var i = 0; i < sketches.length; radio.option(SKETCH + ++i, i));
}
function runPickedSketch() {
activeSketch && destroyMe(activeSketch);
activeSketch = createMe(sketches[this.value() - 1]);
}
function createMe(p) {
return new p5(p);
}
function destroyMe(p) {
p.remove();
}
function hideMe(p) {
p.noLoop();
p._renderer.hide();
return p;
}
function showMe(p) {
p._renderer.show();
p.loop();
return p;
}