为什么在“绘制”过程中,每个点都返回"undefined“而不是一个坐标?在设置过程中不能填充数组吗?
let a = [];
var scl = 10;
class Point {
constructor(i, j) {
this.x = i;
this.y = j;
}
}
function setup() {
createCanvas(600, 600);
for(x = 0; x < width; x += scl) {
a[x] = [];
for(y = 0; y < height; y += scl) {
let p = new Point(x, y);
a[x][y] = p;
}
}
}
function draw() {
background(0);
a.forEach( p => {
rect(p.x, p.y, scl);
});
}发布于 2021-10-11 23:00:11
a是一个二维数组,你需要嵌套循环:
function draw() {
background(0);
a.forEach(row => row.forEach(p => rect(p.x, p.y, scl)));
}https://stackoverflow.com/questions/69533275
复制相似问题