mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Fixed bug in checkerboard creation.
Signed-off-by: npalomba <nicola.palomba@studenti.galileilivorno.gov.it>
This commit is contained in:
parent
cf4f17d891
commit
f229c14d91
@ -1,4 +1,5 @@
|
|||||||
var currentColor = firstCheckerBoardColor;
|
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
|
/* 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.
|
necessary to add a conversion from negative to positive values.
|
||||||
@ -6,23 +7,44 @@ var currentColor = firstCheckerBoardColor;
|
|||||||
|
|
||||||
function fillCheckerboard() {
|
function fillCheckerboard() {
|
||||||
for (var i=0; i<canvasSize[0] / checkerBoardSquareSize; i++) {
|
for (var i=0; i<canvasSize[0] / checkerBoardSquareSize; i++) {
|
||||||
for (var j=0; j<canvasSize[1] / checkerBoardSquareSize; j++) {
|
nSquaresFilled = 0;
|
||||||
context.fillStyle = currentColor;
|
|
||||||
context.fillRect(i * checkerBoardSquareSize, j * checkerBoardSquareSize, checkerBoardSquareSize, checkerBoardSquareSize);
|
|
||||||
|
|
||||||
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) {
|
function changeCheckerboardColor(isVertical) {
|
||||||
if (!rowEndReached) {
|
if (currentColor == firstCheckerBoardColor) {
|
||||||
if (currentColor == firstCheckerBoardColor) {
|
currentColor = secondCheckerBoardColor;
|
||||||
currentColor = secondCheckerBoardColor;
|
} else if (currentColor == secondCheckerBoardColor) {
|
||||||
} else if (currentColor == secondCheckerBoardColor) {
|
currentColor = firstCheckerBoardColor;
|
||||||
currentColor = firstCheckerBoardColor;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,7 +8,6 @@ function line(x0,y0,x1,y1) {
|
|||||||
var err = dx-dy;
|
var err = dx-dy;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
console.log("drawing line");
|
|
||||||
//set pixel
|
//set pixel
|
||||||
if (currentTool == 'pencil') {
|
if (currentTool == 'pencil') {
|
||||||
context.fillRect(x0-Math.floor(brushSize/2), y0-Math.floor(brushSize/2), brushSize, brushSize);
|
context.fillRect(x0-Math.floor(brushSize/2), y0-Math.floor(brushSize/2), brushSize, brushSize);
|
||||||
|
Loading…
Reference in New Issue
Block a user