Spaces:
Sleeping
Sleeping
fix
Browse files- js/interactive_grid.js +21 -2
js/interactive_grid.js
CHANGED
@@ -79,12 +79,31 @@ function handleMouseLeave(event) {
|
|
79 |
function drawGridBefore() {
|
80 |
ctx_bef.clearRect(0, 0, canvas_before.width, canvas_before.height);
|
81 |
drawBackgroundBefore();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
for (let row = 0; row < gridSize; row++) {
|
83 |
for (let col = 0; col < gridSize; col++) {
|
84 |
ctx_bef.beginPath();
|
85 |
ctx_bef.rect(col * cellSizeX, row * cellSizeY, cellSizeX, cellSizeY);
|
86 |
ctx_bef.strokeStyle = 'black';
|
87 |
-
ctx_bef.lineWidth =
|
88 |
ctx_bef.stroke();
|
89 |
|
90 |
if (grid_bef[row][col]) {
|
@@ -105,7 +124,7 @@ function drawGridAfter() {
|
|
105 |
ctx_aft.beginPath();
|
106 |
ctx_aft.rect(col * cellSizeX, row * cellSizeY, cellSizeX, cellSizeY);
|
107 |
ctx_aft.strokeStyle = 'black';
|
108 |
-
ctx_aft.lineWidth =
|
109 |
ctx_aft.stroke();
|
110 |
|
111 |
if (grid_aft[row][col]) {
|
|
|
79 |
function drawGridBefore() {
|
80 |
ctx_bef.clearRect(0, 0, canvas_before.width, canvas_before.height);
|
81 |
drawBackgroundBefore();
|
82 |
+
|
83 |
+
const canvasWidth = canvas_before.width;
|
84 |
+
const canvasHeight = canvas_before.height;
|
85 |
+
|
86 |
+
const bgWidth = canvasBg_bef.width;
|
87 |
+
const bgHeight = canvasBg_bef.height;
|
88 |
+
|
89 |
+
const scaleX = canvasWidth / bgWidth;
|
90 |
+
const scaleY = canvasHeight / bgHeight;
|
91 |
+
|
92 |
+
const scale = Math.min(scaleX, scaleY);
|
93 |
+
|
94 |
+
const newWidth = bgWidth * scale;
|
95 |
+
const newHeight = bgHeight * scale;
|
96 |
+
|
97 |
+
const xOffset = (canvasWidth - newWidth) / 2;
|
98 |
+
const yOffset = (canvasHeight - newHeight) / 2;
|
99 |
+
|
100 |
+
|
101 |
for (let row = 0; row < gridSize; row++) {
|
102 |
for (let col = 0; col < gridSize; col++) {
|
103 |
ctx_bef.beginPath();
|
104 |
ctx_bef.rect(col * cellSizeX, row * cellSizeY, cellSizeX, cellSizeY);
|
105 |
ctx_bef.strokeStyle = 'black';
|
106 |
+
ctx_bef.lineWidth = 0;
|
107 |
ctx_bef.stroke();
|
108 |
|
109 |
if (grid_bef[row][col]) {
|
|
|
124 |
ctx_aft.beginPath();
|
125 |
ctx_aft.rect(col * cellSizeX, row * cellSizeY, cellSizeX, cellSizeY);
|
126 |
ctx_aft.strokeStyle = 'black';
|
127 |
+
ctx_aft.lineWidth = 0;
|
128 |
ctx_aft.stroke();
|
129 |
|
130 |
if (grid_aft[row][col]) {
|