export class MyComponent implements OnInit
{
private p5;
myWidth = 200;
private sketch(p: p5) {
p.setup = () => {
let canvas = p.createCanvas(this.myWidth, this.myWidth);
};
p.draw = function(){
p.background(255);
p.fill(0);
p.rect(p.width / 2, p.height / 2, 50, 50);
};
}
private createTheCanvas() {
this.p5 = new p5(this.sketch);
}
ngOnInit()
{
this.createTheCanvas();
}
}
在这里,错误是this.myWidth未定义
现在的问题是如何在p5的绘图或设置函数中访问MyComponent类中的变量