ughhhh this jawn is so cursed its NOT A BRUTE FORCE it uses a cursed binary search algorithm scratch's color comparison looks at colors with the following bit depths: red: 5 bits green: 5 bits blue: 4 bits LIKE BRO SCRATCH LOCK IN so basically this uses pen to reduce the number of comparisons from what is brute force (2^5 * 2^5 * 2^4) = 16384 comparisons to 5 rounds of 8 comparisons, 5*8 = 40 comparisons. This is a huge speed increase, but unfortunately the pen takes a while to draw. Its still about 10 times faster tho. This would be really fast tho for big pctures as you could do the pen 5 times per fram not per pixel. Becasue scratch is cursed and inconsisten sometime the color detector straight up lies. Yep. It will get a whole bit off, randomly. So thats what the "emergency" shenanigans are for, allowing a maximum of 64 comparisons per round, if you get super unlucky. I don tknow why this glitch happens. But still, worst case scenario, thats 5*64 = 320 comparisons, which is still SO MUCH FASTER than any other algorithm out there, It glitches on average I'd say once per click. and averages needing 32 checks for each glitch. So average comparison count becomes 40-8(included)+32 = 64 comparisons.
um feel free to use this js credit me copy the sprite and use included blocks hoping to use this to create zoom in scratch... lol