etoxin / complementary-colors

Get complementary colors
MIT License
13 stars 4 forks source link

Difference between color and hslColor #7

Open smth opened 2 years ago

smth commented 2 years ago

I was just trying this out and was getting an unexpected result where the returned "primary" colours where slightly different to the inputted base colour. This seems to come down to the base colour having two different values - "color" and "hslColor" (both of which are RGB colours).

For example, if I do var myColor = new compColors('#1ecbe1'), the value of myColor is:

{ "color": { "r": 30, "g": 203, "b": 225 }, "hslColor": { "r": 31, "g": 202, "b": 224 } }

Why the two slightly different RGB values here? A rounding issue? When converting these back to hex it seems the "color" variant is the accurate representation of the original hex. Unfortunately, it is the inaccurate "hslColor" variant that appears to be used in the calculations. So myColor.primary() for example returns [ { "r": 31, "g": 202, "b": 224 } ], and perhaps more importantly, the other colours (complementary etc) are slightly off too.