How can I translate REAL hsv colors into whatever godot uses?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Drawsi

:bust_in_silhouette: Reply From: aipie

I’m not realy sure what you are asking?
Could you give an example of your hsv and equivalent rgb values.

Basically the Color.from_hsv expects the values to be in the range of 0 - 1.
The saturation and the value are already in the 0 to 1 range.
This leaves the hue which is between 0 and 360.
To have it in the range of 0 - 1 you need to divide it by 360.

In the sample you put up there

var c = Color.from_hsv(210/360.0, 0.5, 0.79, 0.8)

Is this what you are looking for?

Well I tried dividing the hue but it just doesn’t work:
I have this color:

HSV: 175°, 43%, 72% - #a shade of cyan

And in Godot it becomes:

175/360, 0.43, 0.72 - #an ugly red

Which are seen as two completely different color.

Drawsi | 2022-04-19 19:59

I have not tested it yet, but it could be of integer division instead of float division.

Can you try with “175.0/360”

aipie | 2022-04-19 20:04

I tried doing this before with the “float” function and it didn’t work. Somehow putting a “.0” did. Thanks a bunch!

Drawsi | 2022-04-19 20:11

I tried doing this before with the “float” function and it didn’t work. Somehow putting a “.0” did.

I assume that’s because you tried something like:

float(175/360)

That won’t work, as it still does integer division, and then coverts the result to a float value. So, you still only have the precision of the original integer result.

Instead, you need to ensure that at least one value in the equation is a float. That can be done line this:

float(175) / 360

… or …

175.0 / 360

jgodfrey | 2022-04-19 20:52

Wouldn’t have though ab that tbh

Drawsi | 2022-04-20 07:27