Anyone know how to get the Hue and Saturation from a color without using simba?
Anyone know how to get the Hue and Saturation from a color without using simba?
[5:53:48 PM] Olly: Kasi its called a brain sir
[5:53:56 PM] Olly: i can work out the hue/mod just by looking at a colour
[5:54:12 PM] Kasi Reddy: genius, tell me how to do it?
[5:55:23 PM] Olly: by going to school, the blue of your skype name has a hue of 0.02 and a sat mod of 1.14
[5:55:43 PM] Steven: meh
[5:55:48 PM] Steven: i dont think i could ever do that
[5:55:56 PM] Steven: mainly cause im colour blind
^skype chat :P
anyway tried googling it? are you able to use other programs to do this?
Well that is the formula, here it is in simba's source: https://github.com/MerlijnWajer/Simb..._conv.pas#L205
As you can see, the integer color is first converted to rgb then to hsl.
I explained it before. But okay, let's do it again cause I am in a good mood ^^
First you take a color, in this example (red: 222, blue: 124, green:180)
We have to convert those components to a percentage. So a number between the 0 and the 1.
redP = 222 / 255;
blueP = 124 / 255;
greenP = 180 / 255;
The we have to get the highest and lowest component. In this case:
lowComp = blueP
highComp = redP
L(lightness) can already be calculated.
L = 0.5 * (highComp + lowComp)
In this case L will be:
L = 0.5 * ((222 / 255) + (124 / 255)) = 0.72156862745098039215686274509804
We then proceed to calculate the difference between the highest and the lowest component.
Diff = highComp - lowComp
In this case that will be:
Diff = (222 / 255) - (124 / 255) = 0,48627450980392156862745098039216
if L(ligtness) is less then 0.5, the sat component can be calculated as:
sat = Diff / (highComp + lowComp)
if the color is darker, and thus L > 0.5, the sat component can be calculated as:
sat = Diff / (2 - highComp - lowComp);
In this case the color is darker, so we use the second formula.
sat = Diff / (2 - (222 / 255) - (124 / 255)) = 0,84722222...2
Jeej!!! Now the only thing to calculate is hue. This is also the hardest one, but let's see. The formula we use depends on which color is highComp.
If highComp is redP then:
hue = ((greenP - blueP ) / Diff) / 6
If highComp is greenP then:
hue = (2 + (blueP - redP ) / Diff) / 6
If highComp is blueP then:
hue = (4 + (redP - greenP ) / Diff) / 6
In this case the highComp is redP. So we use the first formule:
hue = (((180 / 255) - (124 / 255)) / Diff) / 6) = 0,07650273224043715846994535519126
The simba function(RGBToHSL):
Simba Code:program new;
var
h, s, l: Extended;
R, G, B, D, Cmax, Cmin: Extended;
begin
R := 244 / 255;
G := 180 / 255;
B := 124 / 255;
CMin := R;
if G < Cmin then Cmin := G;
if B < Cmin then Cmin := B;
CMax := R;
if G > Cmax then Cmax := G;
if B > Cmax then Cmax := B;
L := 0.5 * (Cmax + Cmin);
if Cmax = Cmin then
begin
H := 0;
S := 0;
end else
begin
D := Cmax - Cmin;
if L < 0.5 then
S := D / (Cmax + Cmin)
else
S := D / (2 - Cmax - Cmin);
if R = Cmax then
H := (G - B) / D
else
if G = Cmax then
H := 2 + (B - R) / D
else
H := 4 + (R - G) / D;
H := H / 6;
if H < 0 then
H := H + 1;
end;
writeln(h);
writeln(s);
writeln(l);
end.
edit:
ninja'd. Reminder to myself, don't spend to much time replying.
Working on: Tithe Farmer
There are currently 1 users browsing this thread. (0 members and 1 guests)