Created
March 8, 2018 17:30
-
-
Save brysonian/9c04e2bcbf020ab4933ba6dc13a1b319 to your computer and use it in GitHub Desktop.
p5 x es6 scope test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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