this question is quick and simple.
I've a 2d array of floats ( 0,0000000 to 1,0000000 ) and i want to convert those numbers to a color value ( #000000 to #ffffff ).
note that i'm talking about just grayscale values.
0 = black | ... | 0.5 = middle gray | ... | 1 = white
does anyone know how to do that with javascript ? thx.
Here is an example using 3 colour to greyscale methods, Lightness, Average and Luminosity.
on jsfiddle
Just be sure to add leading 0's if your value is below 16 and you combine three values into a color code.
Grayscale values in hex are those which got symmetrical distribution or Red, Green and Blue, e.g.: #111111, #5B5B5B, #A2A2A2.
To convert decimal number to hexadecial number you can use:
Put that to function:
So your float can be converted to hex with:
So your function will look like this: