I\'m making a small app where children can fill preset illustrations with colours. I\'ve succesfully implemented an MS-paint style paint bucket using the flood fill argorith
Made something that works:
c = b.getPixel(xx,yy);
if (c == to) continue;
if (c != from) d =
Math.pow(f1 - (c & 0xFF), 2) +
Math.pow(f2 - (c >> 8 & 0xFF), 2) +
Math.pow(f3 - (c >> 16 & 0xFF), 2)
if (c == from || d < tres) {
well, i guess the most natural approach is to calculate the difference between to colors. to achieve a sensible value, one should calculate the difference per channel. haven't tested it, but the following should work:
const perChanThreshold:uint = 5;
const overallThreshold:uint = perChanThreshold * perChanThreshold * 3;
function match(source:uint, target:uint):Boolean {
var diff:uint = 0, chanDiff:uint;
for (var i:int = 0; i < 3; i++) {
chanDiff = (source >> (i * 8)) & 0xFF;
diff += chanDiff * chanDiff;
}
return diff <= overallThreshold;
}