Returns 'Undefined'
Returns 'Undefined'
为什么在“绘制”期间每个点 returns “未定义”而不是坐标?设置时不能填充数组吗?
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);
});
}
a
是二维数组,需要嵌套循环:
function draw() {
background(0);
a.forEach(row => row.forEach(p => rect(p.x, p.y, scl)));
}
为什么在“绘制”期间每个点 returns “未定义”而不是坐标?设置时不能填充数组吗?
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);
});
}
a
是二维数组,需要嵌套循环:
function draw() {
background(0);
a.forEach(row => row.forEach(p => rect(p.x, p.y, scl)));
}