xxxxxxxxxx
/**
* Prototype Graphics (v1.0)
* GoToLoop (2018-Mar-28)
*
* Forum.Processing.org/two/discussion/27465/functions-in-graphics-object#Item_2
*
* OpenProcessing.org/sketch/528626
*/
"use strict";
let pg;
function setup() {
colorMode(RGB).rectMode(CORNER).noLoop();
fill('yellow').stroke('red').strokeWeight(2.5);
p5.prototype.drawRectangle = function (args) {
return this.rect(args);
};
p5.prototype.drawRectangle = p5.prototype.rect; // shorter alternative
pg = createGraphics(width>>1, height>>1);
pg.colorMode(RGB).rectMode(CORNER);
pg.fill('green').noStroke();
pg.drawRectangle(pg.width>>2, pg.height>>2, pg.width>>1, pg.height>>1);
}
function draw() {
background(0o50).drawRectangle(width>>2, height>>2, width>>2, height>>2);
image(pg, width>>1, height>>1);
}