There is a rectangular
grid that will be of size 12 by 12
, in which each corner will be clickable, which is 6*3 cells from each corner of 12*12
grid (single click on any the 4 corners
should select 6*3 cells
), which will be indicated by a color change.
After clicking one of the corners, the remaining cell i.e(144-18 =126)
126 cells, will be checked whether it is equally divisible by a number.
For example,126/6 =21
, so now each 21 part should be represented by a different color. The number which has to be checked against depends upon the user, if the user gives a number which is not divisible, it will not show any change.
The logic I tried to apply is, I created a multidimensional array of size 12*12
, which contains full of zero's. when the user passes one of the corner coordinates 6*3
cell will turn to one. But I don't know how to implement this logic in html
canvas, also how to proceed further.
addBed = (x, y) => {
let test = Array(12).fill(0).map(x => Array(12).fill(0));
let bedX = 3, bedY = 6; // BED AREA = 6*3
let dx = 1, dy = 1;
let endX = bedX, endY = bedY;
const roomX = 11, roomY = 11
if (x === roomX) {
dx = -1
endX = roomX - bedX
}
if (y === roomY) {
dy = -1
endY = roomY - bedY
}
for (let i = x; dx === 1 ? i < endX : i > endX; i += dx) {
for (let j = y; dy === 1 ? j < endY : j > endY; j += dy) {
test[i][j] = 1;
}
}
console.log(test)
// this.setState({ testMap: test });
}
addBed(0, 0); // this will make the first corner to be turned to 1