Fixed infinite loop when filling an area with the same colour

This commit is contained in:
unsettledgames 2021-06-30 22:35:46 +02:00
parent aea3942349
commit 1a69b48297
2 changed files with 6 additions and 3 deletions

View File

@ -41,13 +41,17 @@ function fill(cursorLocation) {
//the new color to fill with
var fillColor = hexToRgb(currentLayer.context.fillStyle);
console.log("here");
//if you try to fill with the same color that's already there, exit the function
if (clusterColor[0] == fillColor.r &&
clusterColor[1] == fillColor.g &&
clusterColor[2] == fillColor.b &&
clusterColor[3] == fillColor.a)
clusterColor[3] != 0) {
console.log("Returned");
return;
}
//loop until there are no more values left in this array
while (topmostPixelsArray.length) {

View File

@ -231,7 +231,6 @@ function draw (mouseEvent) {
//draw line to current pixel
if (dragging) {
if (mouseEvent.target.className == 'drawingCanvas' || mouseEvent.target.className == 'drawingCanvas') {
console.log("Mouse coords: " + (cursorLocation[0] / zoom) + "," + cursorLocation[1] / zoom);
line(Math.floor(lastMouseClickPos[0]/zoom),
Math.floor(lastMouseClickPos[1]/zoom),
Math.floor(cursorLocation[0]/zoom),