Replace Color - HSL

0 favourites
• 23 posts
From the Asset Store
HSV RGB Color Picker and Converter for Construct 3
• Hey, I am making a menu that allows you to change how your character looks. You can change the color of some things, such as the eye color. I have three custom sliders, one for Hue, one for Saturation, and one for Vibrance. In RGB there are either three 255s or three 100s, but in HSL there are two 100s and a 360. My Hue slider's max is 360, and my Sat and Vib sliders are max 100. I have the "ReplaceColor" effect, but it is in RGB. I need it to be in HSL. How to I convert it?

Thanks,

Give me a Pixel

Tagged:

• It is possible.. its not a single line of code but yeah..

Here:

``````function rgb2hue(r, g, b) {
r /= 255;
g /= 255;
b /= 255;
var max = Math.max(r, g, b);
var min = Math.min(r, g, b);
var c = max - min;
var hue;
if (c == 0) {
hue = 0;
} else {
switch(max) {
case r:
var segment = (g - b) / c;
var shift = 0 / 60; // R° / (360° / hex sides)
if (segment < 0) { // hue > 180, full rotation
shift = 360 / 60; // R° / (360° / hex sides)
}
hue = segment + shift;
break;
case g:
var segment = (b - r) / c;
var shift = 120 / 60; // G° / (360° / hex sides)
hue = segment + shift;
break;
case b:
var segment = (r - g) / c;
var shift = 240 / 60; // B° / (360° / hex sides)
hue = segment + shift;
break;
}
}
return hue * 60; // hue is in [0,6], scale it up
}
``````
• Whoa that looks complex! And I don't know JavaScript, but I'll give it a try.

Thank you.

• Whoa that looks complex! And I don't know JavaScript, but I'll give it a try.

Thank you.

It`s possible to create the same script as C3 function.. it's basically comparison and basic math.

:)

• Well, ok. I'll see what I can do. Can you just copy and paste everything into a C3 function or do I have to do some conversions?

• Can you share your project? Let me try creating it as C3 function instead of code..

• Mate, sorry, I think i misunderstood it.. You have HSL you NEED RGB and I sent you the opposite

right?

• Yeah, I have three sliders: Hue, Sat, Vib, and I need to get them into RGB so I can use the "ReplaceColor" effect. Actually, I didn't even think about what you sent being wrong until you pointed it out :). Glad you caught it. I can still create a minimal demo if you need it.

• Can you make sure that you have HUE, SAT and Lum (HSL) as you said HSL but also HSV (Vib), just to make sure which math to use..

Im trying to create a function here to convert from HSL to RGB.

• HSl and HSV are the same thing. One stands for vibrance and one for lumocity. No difference. Here is the minimal file:

dropbox.com/s/7nuoubx9cbzdja1/Replace%20Color%20-%20HSL%20Demo.c3p

• Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• I too have a template (paid) that can convert HSV<>RGB, and pick colors:

howtoconstructdemos.com/hsv-color-picker-tool-c3p

• Thank you, I'll check it out.

• Dop2000

I generally do not spend money on things like this, but I'll keep your example in mind. Thanks anyway.

• Here is the converter bit:

dropbox.com/s/exg0z5ncs4qy9n0/HSV-RGB-ConvertOnly.c3p

• Thank you so much! You were so helpful.

• 23 posts