I’m writing a script that needs hexadecimal color input, sometimes referred to as a web color, converted to a value usable for a solid in After Effects. After Effects wants an array of RGB values in the range 0 to 1: [R, G, B]. Luckily Javascript supports bit-wise operators so the conversion is pretty straight forward. I used this function.
var hex = 'ffaadd'; var colors = hexToRGBArray(hex); alert("red =" + colors[0] + " green=" + colors[1] + " blue=" + colors[2]); function hexToRGBArray(hex){ var rgb = parseInt(hex, 16); var red = (rgb >>16) & 0xFF; var green = (rgb >>8) & 0xFF; var blue = rgb & 0xFF; var colorArray = [red/255.0, green/255.0, blue/255.0]; return colorArray; }