Soft Paint Bucket Fill: Colour Equality

后端 未结 2 1260
自闭症患者
自闭症患者 2021-01-07 09:34

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

2条回答
  •  甜味超标
    2021-01-07 10:24

    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;
    }
    

提交回复
热议问题