Why do you need to determine dynamically where can be constructed? I'd say it's much easier to determine this in advance per background, or maybe even better, use tiles that are randomly combined.
If not, I'd convert the color to HSB (Hue, Saturation, Brightness). You can determine hue intervals to distinguish the "color", then with further intervals you can restrict the brightness and saturation in order to exclude shades of gray, etcetera. Does this help you?
But I can't convert RGB to HSI (and, HSI to RGB) because I can't find a readable algorithm (or understandable in my coding language) or even understand the formulae.
Hmmm... I've done that conversion a long time ago in PostScript, but I doubt that code would be a big help to you, even if I'd still have it. Unfortunately, I can't give you the formulae off-hand either.
I found a very good formulae, but what in h*ell means cos raised to -1 ?
It is a common alternative way to write arc cos. (It was written that way on the keyboard of HP calculators for instance, if I recall it correctly.) But it may also mean 1/cos. I think it should be possible to determine from the context which one is meant, provided some math background.
In file is shown 1.167π, but if I multiply the whole math by 2π I get different results.
I'm not quite sure what you're referring to, but I think it's step two of the example conversion on page 2 of that PDF file, because that's the only place where I see a 1.167π in there.
If I repeat the calculation, I get exactly the result that's shown there. Are you sure you set your calculator to radians rather than degrees? And, BTW, I don't see anything there that says you should multiply whatever with 2π.