Skip to content

Instantly share code, notes, and snippets.

@brysonian
Created March 8, 2018 17:30
Show Gist options
  • Select an option

  • Save brysonian/9c04e2bcbf020ab4933ba6dc13a1b319 to your computer and use it in GitHub Desktop.

Select an option

Save brysonian/9c04e2bcbf020ab4933ba6dc13a1b319 to your computer and use it in GitHub Desktop.
p5 x es6 scope test
class Sketch {
_fillColor = [0, 0, 0, 255];
_width = 200;
_height = 200;
setup() {}
draw() {}
createCanvas = (width, height) => {
this._width = width;
this._height = height;
}
fill = (red = false, green = red, blue = red, alpha = 255) => {
if (red !== false) {
this._fillColor = [red, green, blue, alpha];
}
return this._fillColor;
}
rect = (x, y, w, h) => {
console.log(`Draw a rect: ${x}, ${y}, ${w}, ${h}`);
}
}
class p5 {
static instances = [];
static attach(sketch) {
p5.instances.push(sketch);
}
static run() {
p5.instances.forEach((sketch) => {
sketch.setup();
});
setInterval(this.update, 250);
}
static update() {
p5.instances.forEach((sketch) => {
sketch.draw();
});
}
}
p5.Sketch = Sketch;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment