Random colour
Cubist at aol.com
Cubist at aol.com
Mon Jun 9 22:55:00 EDT 2003
To randomly generate pairs of colors which guarantee that text in Color A
will be readable against background of Color B... hmmm.
Since Rev allows colors to be specified as RGB, i.e. a trio of integers in
the range 0 to 255, it seems to me that something like this might be suitable:
function ColorPair
put random (256) - 1 into RGB_1_1
put random (256) - 1 into RGB_1_2
put random (256) - 1 into RGB_1_3
put 50 into ColorMargin
# if 50 isn't enough of a margin, change it to something else
put random (256 - ColorMargin) - 1 into RGB_2_1
if RGB_2_1 > (RGB_1_1 - ColorMargin) then add 2*ColorMargin to RGB_2_1
put random (256 - ColorMargin) - 1 into RGB_2_2
if RGB_2_2 > (RGB_1_2 - ColorMargin) then add 2*ColorMargin to RGB_2_2
put random (256 - ColorMargin) - 1 into RGB_2_3
if RGB_2_3 > (RGB_1_3 - ColorMargin) then add 2*ColorMargin to RGB_2_3
return RGB_1_1,RGB_1_2,RGB_1_3,RGB_2_1,RGB_2_2,RGB_2_3
end ColorPair
Alternately, perhaps you could use 0-127 for the RGB_1_x values, and 128
-255 for the RGB_2_x values?
Hope this helps...
More information about the use-livecode
mailing list