mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Added comments, removed unused variables.
Signed-off-by: npalomba <nicola.palomba@studenti.galileilivorno.gov.it>
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user