Fixed bug in checkerboard creation.

Signed-off-by: npalomba <nicola.palomba@studenti.galileilivorno.gov.it>
This commit is contained in:
npalomba 2019-03-31 15:10:51 +02:00
parent cf4f17d891
commit f229c14d91
2 changed files with 34 additions and 13 deletions

View File

@ -1,4 +1,5 @@
var currentColor = firstCheckerBoardColor;
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.
@ -6,23 +7,44 @@ var currentColor = firstCheckerBoardColor;
function fillCheckerboard() {
for (var i=0; i<canvasSize[0] / checkerBoardSquareSize; i++) {
for (var j=0; j<canvasSize[1] / checkerBoardSquareSize; j++) {
context.fillStyle = currentColor;
context.fillRect(i * checkerBoardSquareSize, j * checkerBoardSquareSize, checkerBoardSquareSize, checkerBoardSquareSize);
nSquaresFilled = 0;
changeCheckerboardColor(false);
for (var j=0; j<canvasSize[1] / checkerBoardSquareSize; j++) {
var rectX;
var rectY;
if (i * checkerBoardSquareSize < canvasSize[0]) {
rectX = i * checkerBoardSquareSize;
}
else {
rectX = canvasSize[0];
}
if (j * checkerBoardSquareSize < canvasSize[1]) {
rectY = j * checkerBoardSquareSize;
}
else {
rectY = canvasSize[1];
}
context.fillStyle = currentColor;
context.fillRect(rectX, rectY, checkerBoardSquareSize, checkerBoardSquareSize);
changeCheckerboardColor();
nSquaresFilled++;
}
changeCheckerboardColor(false);
if ((nSquaresFilled % 2) == 0) {
changeCheckerboardColor();
}
}
}
function changeCheckerboardColor(rowEndReached) {
if (!rowEndReached) {
if (currentColor == firstCheckerBoardColor) {
currentColor = secondCheckerBoardColor;
} else if (currentColor == secondCheckerBoardColor) {
currentColor = firstCheckerBoardColor;
}
function changeCheckerboardColor(isVertical) {
if (currentColor == firstCheckerBoardColor) {
currentColor = secondCheckerBoardColor;
} else if (currentColor == secondCheckerBoardColor) {
currentColor = firstCheckerBoardColor;
}
}

View File

@ -8,7 +8,6 @@ function line(x0,y0,x1,y1) {
var err = dx-dy;
while (true) {
console.log("drawing line");
//set pixel
if (currentTool == 'pencil') {
context.fillRect(x0-Math.floor(brushSize/2), y0-Math.floor(brushSize/2), brushSize, brushSize);