I have a number between 0.0 and 1.0, I would like to convert it to a grayscale color.
White = 0
Black = 1
You can show me how in any understandable language (I prefer actionscript 3)
Please, don't just give a name of a function that a language have to do this, I want to know how it does.
views:
102answers:
2
A:
Hi
In Mathematica, like this
GrayLevel[0.25]
supposing your number is 0.25, of course.
Regards
Mark
High Performance Mark
2010-01-31 03:55:26
Unfortunatly, I am using actionscript 3, it is not possible there :(
M28
2010-01-31 04:03:30
+1
A:
Assuming 0 as black and 1 as white, this AS3 function receives a number (from 0 to 1) and returns a hex number with a grayscale color
public static function num2gray(n:Number):Number {
var gray:Number = n * 255;
return(gray << 16 | gray << 8 | gray);
}
mga
2010-01-31 04:10:51
you could also try this for `#RRGGBB` results: function num2gray(n:Number):String { var gray:Number = n * 255; var gg:String = (gray.toString(16).length < 2) ? "0" + gray.toString(16) : gray.toString(16); return("#" + gg + "" + gg + "" + gg); }
mga
2010-01-31 04:35:38