In a game, we use a technique called \'colour picking\' to select units.
This means that every visible unit is given a unique colour.
Here is an example of a
It seems to me that what's important is that the contrast between units which are close to each other is high enough, i.e. I would try to come up with some way to take the proximity of units into account.
For instance, you could take the X/Y coordinates of the units into account such that coordinates which are close to each other get colors with a high contrast, low contrast is only used for units which are sufficiently far away.
A first shot might be to have a simple array a
of 256 colors such that there's a large contrast between a[n]
and a[n+1]
. You can then pick the color of units by using their X and/or Y coordinate modulo 256 as the index into the array. That way, you will get colors reused for units which are at least 256 pixels (or whatever metric you may use) apart, but different colors for units which are very close to each other.