0
P5 is a canvas creation and animation lib.
I got an error when I couldn’t find a variable from a constructor function "sister".
Looking at the sk.draw()
Function, the error occurs when this function is searching for a function variable above: sk.setup
, How do I pull the variable b
of the scope of sk.setup
for the scope of my sk.draw function()` ?
follows the code below.
/* eslint-disable */
import * as p5 from 'p5'
let sketch = (p5) => {
console.log(p5)
class Boundary {
constructor(x1, y1, x2, y2) {
this.a = p5.createVector(x1, y1);
this.b = p5.createVector(x2, y2);
}
show = () => {
p5.stroke(255);
p5.line(this.a.x, this.a.y, this.b.x, this.b.y);
};
}
p5.setup = () => {
// eslint-disable-next-line
let b
p5.createCanvas(window.innerWidth, window.innerHeight);
b = new Boundary(300, 100, 300, 300);
};
p5.draw = () => {
p5.background(0);
b.show();
}
}
const P5 = new p5(sketch);
export default P5