From cd3303e21201388c9f5ad15bfd21691c3ecd7e63 Mon Sep 17 00:00:00 2001 From: unsettledgames <47360416+unsettledgames@users.noreply.github.com> Date: Mon, 28 Jun 2021 22:03:57 +0200 Subject: [PATCH] Fixed fill bug --- js/_fill.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/js/_fill.js b/js/_fill.js index 22d0f44..e40bd97 100644 --- a/js/_fill.js +++ b/js/_fill.js @@ -16,8 +16,9 @@ function fill(cursorLocation) { var r = tempImage.data[pixelPos]; var g = tempImage.data[pixelPos + 1]; var b = tempImage.data[pixelPos + 2]; + var a = tempImage.data[pixelPos + 3]; //console.log(r == color[0] && g == color[1] && b == color[2]); - return (r == color[0] && g == color[1] && b == color[2]); + return (r == color[0] && g == color[1] && b == color[2] && a == color[3]); } //save history state @@ -36,7 +37,7 @@ function fill(cursorLocation) { var startingPosition = (topmostPixelsArray[0][1] * canvasSize[0] + topmostPixelsArray[0][0]) * 4; //the color of the cluster that is being filled - var clusterColor = [tempImage.data[startingPosition],tempImage.data[startingPosition+1],tempImage.data[startingPosition+2]]; + var clusterColor = [tempImage.data[startingPosition],tempImage.data[startingPosition+1],tempImage.data[startingPosition+2], tempImage.data[startingPosition+3]]; //the new color to fill with var fillColor = hexToRgb(currentLayer.context.fillStyle); @@ -44,7 +45,8 @@ function fill(cursorLocation) { //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[2] == fillColor.b && + clusterColor[3] == fillColor.a) return; //loop until there are no more values left in this array