Random colour
Dar Scott
dsc at swcp.com
Mon Jun 9 13:24:01 EDT 2003
On Monday, June 9, 2003, at 10:16 AM, David Squance wrote:
> Is there a simple way to randomize color of text and background of a
> field
> without getting a combination which is unreadable?
One approach is to randomly choose two colors until you get a readable
combination. You may want to return black & white if something goes
wrong and after a hundred tries you don't get an readable combination.
One approach to readability is contrast.
If handling color blindness is a priority, then map the colors into an
appropriate 2D or 1D space for contrast analysis. An easy 1D is
brightness. Distance is also easy to calculate in 1D; no squares or
square roots are involved.
You may want to map to a psychological space, but I think RGB space
should work in most cases.
To calculate the distance sum the squares of the deltas in each
dimension and take the square root of that. Consider a combination
readable if the distance is above some threshold.
You may want a higher threshold if text is lighter than the background.
You can avoid the square root if you square your threshold and compare
against that.
To randomly choose a color, randomly choose each of the RGB values.
Is this the direction you were thinking?
Dar Scott
More information about the use-livecode
mailing list