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: , , , ,

3 Responses to “HowTo: Create hexidecimal grayscale integers”

  1. Owen Says:

    you can also use hex numbers as the multiplier :)
    ie num * 0xFFFFFF

  2. Owen Says:

    although, of course, the code I just posted means you should use a value between 0 and 1

  3. rich Says:

    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;

Leave a Reply