HTML and CSS Reference
In-Depth Information
if (Grid[i][j] === 1) {
paintCell(ctx,
j * cellWidth,
i * cellHeight,
cellWidth,
cellHeight);
// Print the current values of i and j for each cell
ctx.fillStyle = '#000';
ctx.font = '10px Arial';
ctx.textAlign = 'center';
ctx.fillText(i + ' ' + j,
j * cellWidth,
i * cellHeight);
// Set that position as painted
Grid[i][j] = 0;
}
}
}
// There's no need to go through all this logic on every frame
shouldRepaint = false;
// Set the previous timestamp, which will be used
// in the "next" loop.
// Subtract the difference between the delta and the interval
// to account for the time that it took the computer to
// process the function.
previousTs = ts - (delta % interval);
}
// Call requestAnimationFrame again
requestAnimationFrame(update);
}
function paintCell(ctx, x, y, w, h) {
// Set the background colour to white
ctx.fillStyle = '#fff';
// Draw the background
ctx.fillRect(x, y, w, h);
Search WWH ::




Custom Search