Skip to content

Instantly share code, notes, and snippets.

@GoSubRoutine
Last active July 27, 2017 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GoSubRoutine/ce702dbf832b11732ddae6b7c7d49f9d to your computer and use it in GitHub Desktop.
Save GoSubRoutine/ce702dbf832b11732ddae6b7c7d49f9d to your computer and use it in GitHub Desktop.
Instance Mode Multi-Files
height: 200
<script defer src=http://CDN.JSDelivr.net/npm/p5></script>
<script defer src=mouseHandler.js></script>
<script defer src=sketch.js></script>
"use strict";
var imports;
void function (imports) {
function mousePressed() {
const inc = this.mouseButton === this.LEFT && -1 || 1;
this.a = this.constrain(this.a + inc, -1, 100);
console.log(this.a);
this.redraw();
}
imports.mousePressed = mousePressed;
}(imports || (imports = {}));
/**
* Instance Mode Multi-Files (v1.7.1)
* GoToLoop (2017-Jul-26)
*
* Forum.Processing.org/two/discussion/23580/
* instance-mode-over-multiple-files#Item_1
*
* Bl.ocks.org/GoSubRoutine/ce702dbf832b11732ddae6b7c7d49f9d
*/
"use strict";
void function () {
const s = new p5(p => {
let a = ~~p.random(100);
Object.defineProperty(p, 'a', {
get() { return a; }, set(n) { a = n; },
enumerable: true, configurable: false
});
p.setup = function () {
this.createCanvas(300, 200);
this.noLoop();
this.colorMode(this.RGB).blendMode(this.BLEND);
this.fill('yellow').stroke('red').strokeWeight(2.5);
this.textAlign(this.CENTER, this.CENTER).textSize(0o200);
};
function draw() {
this.background('#' + this.hex(~~this.random(0x1000), 3));
this.text(a, this.width>>1, this.height>>1);
}
p.draw = draw.bind(p);
}, 'canvas-holder');
s.mousePressed = imports.mousePressed;
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment