Skip to content

Commit

Permalink
improved readability on small cell sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
TGianella committed Jan 9, 2024
1 parent f64e11d commit 7490137
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
16 changes: 11 additions & 5 deletions app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ export const logoUrls = {
}

export const colors = {
gridColor: {
value: "#CCCCCC",
},
gridColorLarge: {
value: "#CCCCCC",
},
gridColorMedium: {
value: "#EEEEEE",
},
gridColorSmall: {
value: "#fcfcfc",
},
aliveColor: {
value: "#FFFFFF",
continueCondition: false,
},
},
deadColor: {
value: "#000000",
continueCondition: true,
}
},
}
1 change: 1 addition & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

canvas {
border: solid black 1px;
image-rendering: pixelated;
}

label {
Expand Down
7 changes: 4 additions & 3 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const loopShouldReset = () => {

const nextFrame = () => {
if (isPaused(animationId)) {
drawGrid(ctx, width, cellSize, height);
// drawGrid(ctx, width, cellSize, height);
drawCells(ctx, universe, memory, width, height, cellSize, importUniverse, checkCell);
universe.tick();
generationsCount = updateGenerationsCount(generationsCount,1);
Expand Down Expand Up @@ -172,6 +172,7 @@ const modifyBoard = (label, value, resize) => {
generationsCount = resetTimerAndGenerations();
}

drawGrid(ctx, width, cellSize, height);
drawCells(ctx, universe, memory, width, height, cellSize, importUniverse, checkCell);
}

Expand Down Expand Up @@ -243,7 +244,7 @@ canvas.addEventListener("click", event => {
drawPattern(universe, pulsar, row, col);
}

drawGrid(ctx, width, cellSize, height);
// drawGrid(ctx, width, cellSize, height);
drawCells(ctx, universe, memory, width, height, cellSize, importUniverse, checkCell);
});

Expand All @@ -260,7 +261,6 @@ function renderLoop() {
fps.render();
generationsCount = updateGenerationsCount(generationsCount, ticksFrequency);

drawGrid(ctx, width, cellSize, height);
drawCells(ctx, universe, memory, width, height, cellSize, importUniverse, checkCell);

for (let i = 0; i < ticksFrequency; i++) {
Expand All @@ -274,4 +274,5 @@ function renderLoop() {
animationId = requestAnimationFrame(renderLoop);
}

drawGrid(ctx, width, cellSize, height);
play();
12 changes: 11 additions & 1 deletion app/utils/draw.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,19 @@ export const drawCells = (ctx, universe, memory, width, height, cellSize, import
ctx.stroke();
}

const setGridColor = (ctx, cellSize) => {
if (cellSize > 3) {
ctx.strokeStyle = colors.gridColorLarge.value;
} else if (cellSize > 1) {
ctx.strokeStyle = colors.gridColorMedium.value;
} else {
ctx.strokeStyle = colors.gridColorSmall.value;
}
}

export const drawGrid = (ctx, width, cellSize, height) => {
ctx.beginPath();
ctx.strokeStyle = colors.gridColor.value;
setGridColor(ctx, cellSize);

// Vertical lines.
for (let i = 0; i <= width; i++) {
Expand Down

0 comments on commit 7490137

Please sign in to comment.