convert and calculate colors in JavaScript