I can't seem to find reference for converting RGB values to the value range that javascript needs [0.0-1.0].
Any help would be greatly appreciated. Thanks.
[Solved] How do I convert RGB to value range 0.0-1.0?
Moderator: Paul Tuersley
-
- Posts: 704
- Joined: June 5th, 2004, 7:59 am
- Location: London, UK
If the values are 8 bit 0-255 you would just divide each rgb value by 255.
-
- Posts: 704
- Joined: June 5th, 2004, 7:59 am
- Location: London, UK
You can use parsetInt(yourHexString, 16) to convert from hex to decimal.
Okay, I'm a little confused still...
How would the parseInt() work in this scenario?
How would the parseInt() work in this scenario?
Code: Select all
//Convert HEX to RGB_______________________________________________________________________________________________
function GiveDec(Hex)
{
if(Hex == "A")
Value = 10;
else
if(Hex == "B")
Value = 11;
else
if(Hex == "C")
Value = 12;
else
if(Hex == "D")
Value = 13;
else
if(Hex == "E")
Value = 14;
else
if(Hex == "F")
Value = 15;
else
Value = eval(Hex);
return Value;
}
function HexToDec()
{
lastNameColor = lastNameColor.toUpperCase(); //change all lowercase letters to uppercase
var a = GiveDec(lastNameColor.substring(0, 1));
var b = GiveDec(lastNameColor.substring(1, 2));
var c = GiveDec(lastNameColor.substring(2, 3));
var d = GiveDec(lastNameColor.substring(3, 4));
var e = GiveDec(lastNameColor.substring(4, 5));
var f = GiveDec(lastNameColor.substring(5, 6));
redValue = (a * 16) + b;
greenValue = (c * 16) + d;
blueValue = (e * 16) + f;
//convert RGB values to decimal values
var redDecimal = (redValue/2.55)/100;
var greenDecimal = (greenValue/2.55)/100;
var blueDecimal = (blueValue/2.55)/100;
}
//__________________________________________________________________________________________________________
//Set color for last name (Animator on text layer: Fill Color)
var colorLastName= lastNameLayer.property("Text").property("Animators").property("Animator 1").property("Properties").property("Fill Color");
colorLastName.setValue([redDecimal, greenDecimal, blueDecimal, 1]);
//____________________________________________________________________________________________________
-
- Posts: 320
- Joined: June 26th, 2004, 10:01 am
- Location: Folsom, CA
- Contact:
I think all you need is something like this:
redSubstr = lastNameColor.substr(0,2);
greenSubstr = lastNameColor.substr(2,2);
blueSubstr = lastNameColor.substr(4,2);
redDecimal = parseInt(redSubstr,16)/255;
greenDecimal = parseInt(greenSubstr,16)/255;
blueDecimal = parseInt(blueSubstr,16)/255;
Dan
redSubstr = lastNameColor.substr(0,2);
greenSubstr = lastNameColor.substr(2,2);
blueSubstr = lastNameColor.substr(4,2);
redDecimal = parseInt(redSubstr,16)/255;
greenDecimal = parseInt(greenSubstr,16)/255;
blueDecimal = parseInt(blueSubstr,16)/255;
Dan