Stroep

Just a collection of random works – Mark Knol

Grayscale color (0)

August 22nd, 2008, under Actionscript.

My first post :D Just testing the syntax highlighting too. It works perfect!

This is how I create a grayscale color in actionscript 3.

grayscale ( 140 );
 

The function:

/*
* Get a grayscale color from a tint
*
* @param tint Enter tint from range 0 to 255
* @return Gray hexadecimal colorvalue
* @tiptext
*/

public static function grayscale ( tint:uint = 0 ):uint
{
    // restriction
    if (tint < 0) { tint = 0 }
    if (tint > 255) { tint = 255 }
    // return calculation of color
    return (tint << 16) | (tint << 8) | tint;
}

Feel free to add comment

Tagged with , . | Tiny URL http://tinyurl.com/cfkb8w

Leave a Reply