1

I'm trying to make a simple conversion with color.js from this library, and I can't seem to do it. I tried dong the following:

var myColor = new Colors(); var hslColor = myColor.colorConverter.hsv2hsl({ h: 100, s: 100, v: 100 }); 

But I get an error:

Uncaught TypeError: Cannot read property 'hsv2hsl' of undefined

Why am I getting the error, and how can I fix it?

JSFiddle

Code Snippet

var myColor = new Colors(); var hslColor = myColor.colorConverter.hsv2hsl({ h: 100, s: 100, v: 100 }); console.log(hslColor);
<script src="https://rawgit.com/PitPik/colorPicker/master/colors.js"></script>

3 Answers 3

5

An instance of Colors doesn't have a colorConverter property.

Sign up to request clarification or add additional context in comments.

2 Comments

I was right about to post the same answer -- ColorConverter looks to be a private utility within the closure, and isn't accessible directly by anything trying to use Colors
See @Shy A's answer. It most definitely does!
1

Just dig in a little bit and found the right way

var myColor = new Colors(); var hslColor = myColor.convertColor({ h: 100, s: 100, v: 100 },'hsv2hsl') 

3 Comments

When I do that, I get weird results. The result of the above code snippet is: h: 100, s: -1.0204081632653061, l: -4900 jsfiddle.net/3eavjrgL/1
i took the convert function from colors.js and test it and got the same result, so the problem is in the colors.js **[check here]**(jsfiddle.net/puemos/q9at4kLq)
convertColor is case sensitive: hsv means components from 0 to 1 whereas HSV means H: 0 - 360, S: 0 - 100, V: 0 - 100. So you probably wanted to convert from HSV2HSL not from hsv2hsl (You can also use hsv2HSL or HSV2hsl)
0

myColor.colorConverter doesn't exist. The right way is to use myColor's method convertColor(). The second argument of convertColor() is case sensitive:

var myColor = new Colors(); var hslColor = myColor.convertColor({ h: 100, s: 100, v: 100 },'HSV2HSL'); // not 'hsv2hsl' 

hsv means components from 0 to 1 whereas HSV means H: 0 - 360, S: 0 - 100, V: 0 - 100. So you probably want to convert from HSV2HSL not from hsv2hsl

You can also mix it like hsv2HSL or HSV2hsl.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.