Added comments, removed unused variables.

Signed-off-by: npalomba <nicola.palomba@studenti.galileilivorno.gov.it>
This commit is contained in:
npalomba
2019-04-01 21:37:53 +02:00
parent 8f4f4c2478
commit f7100ff9f7
6 changed files with 32 additions and 13 deletions

View File

@@ -1,13 +1,15 @@
// This script contains all the functions used to manage the checkboard
// Setting current colour (each square has a different colour
var currentColor = firstCheckerBoardColor;
// Saving number of squares filled until now
var nSquaresFilled = 0;
/* TODO add check for canvas dimentions (right now negative values can be inserted and a canvas will be generated, it is just
necessary to add a conversion from negative to positive values.
*/
function fillCheckerboard() {
// Getting checkerboard context
var context = checkerBoard.context;
// Cycling through the canvas (using it as a matrix)
for (var i=0; i<canvasSize[0] / checkerBoardSquareSize; i++) {
nSquaresFilled = 0;
@@ -15,6 +17,7 @@ function fillCheckerboard() {
var rectX;
var rectY;
// Managing the not perfect squares (the ones at the sides if the canvas' sizes are not powers of checkerBoardSquareSize
if (i * checkerBoardSquareSize < canvasSize[0]) {
rectX = i * checkerBoardSquareSize;
}
@@ -29,20 +32,24 @@ function fillCheckerboard() {
rectY = canvasSize[1];
}
// Selecting the colour
context.fillStyle = currentColor;
context.fillRect(rectX, rectY, checkerBoardSquareSize, checkerBoardSquareSize);
// Changing colour
changeCheckerboardColor();
nSquaresFilled++;
}
// If the number of filled squares was even, I change colour for the next column
if ((nSquaresFilled % 2) == 0) {
changeCheckerboardColor();
}
}
}
// Simply switches the checkerboard colour
function changeCheckerboardColor(isVertical) {
if (currentColor == firstCheckerBoardColor) {
currentColor = secondCheckerBoardColor;