HowTo: Create hexidecimal grayscale integers
This turns out to be outrageously simple. If you wanna create a grayscale somewhere between pure black and pure white all you need is this could-not-be-simpler equation:
var num:int = 1; // any int from 0 to 255 var grayscale:int = num * 65793;
All you need to ensure is that the value of ‘num’ is an integer from 0 (for pure black) to 255 (for pure white) and that’s it!
Tags: AS3, grayscale, greyscale, hex, hexidecimal
November 19th, 2008 at 10:08 am
you can also use hex numbers as the multiplier :)
ie num * 0xFFFFFF
November 19th, 2008 at 10:09 am
although, of course, the code I just posted means you should use a value between 0 and 1
February 25th, 2009 at 9:23 am
Math.random() * 0xFFFFFF will not produce a colour balance where r, g and b are all equal. to ensure this you have to use:
int (0-255) * 65793;