Skip to content

Instantly share code, notes, and snippets.

@martinwairegi
Created July 5, 2022 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinwairegi/3cf814b19545f511550aac3fa5106b93 to your computer and use it in GitHub Desktop.
Save martinwairegi/3cf814b19545f511550aac3fa5106b93 to your computer and use it in GitHub Desktop.
const gridBlockSize = 100;
const gridWidth = Math.floor(window.innerWidth / gridBlockSize);
const gridHeight = Math.floor(window.innerHeight / gridBlockSize);
const gridRGBs = [];
export default function gridReducer(grid, action) {
switch (action.type) {
case "BUILD_GRID":
for (let widthIndex = 0; widthIndex < gridWidth; widthIndex++) {
const gridColumn = [];
for (let heightIndex = 0; heightIndex < gridHeight; heightIndex++) {
gridColumn[heightIndex] = "255, 255, 255";
}
gridRGBs[widthIndex] = gridColumn;
}
return {
blockSize: gridBlockSize,
width: gridWidth,
height: gridHeight,
RGBs: gridRGBs
};
case "CHANGE_GRID_BLOCK_COLOR":
grid.RGBs[action.position[0]][action.position[1]] = action.rgb;
return grid;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment