I am trying to figure out a way to slice out a 2d array section from a 2d array.
I am looking for an efficient way to create another 2d array from the coordinate locations (4,5) to (7,10). The area you see as 1s in the array.
var arr = [
[0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,1,1,1,1,1,0],
[0,0,0,0,0,1,1,1,1,1,0],
[0,0,0,0,0,1,1,1,1,1,0],
[0,0,0,0,0,0,0,0,0,0,0],
];
var successfulCropOfArray = [
[1,1,1,1,1],
[1,1,1,1,1],
[1,1,1,1,1]
];
Does anybody have any pseudo code available for how I could accomplish this. Here is what I've tried with little to no success:
var slicedMap = Create2DArray(visibleMap);
var topLeftCorner = {
x: 4,
y: 5
};
var bottomRightCorner = {
x: 10,
y: 7
};
for(var left = topLeftCorner.x;left<bottomRightCorner.x;left++) { //from left to right scan
for(var top = bottomRightCorner.y-visibleMap;top>bottomRightCorner.y;top--) {
for(var slicedX = 0;slicedX<slicedMap.length;slicedX++) {
for(var slicedY = 0;slicedY<slicedMap.length;slicedY++) {
slicedMap[slicedY][slicedX] = rooms[newroom].map[bottom][left];
}
}
}
}