Kasi
2012-11-06 13:25:11
Anyone know how to get the Hue and Saturation from a color without using simba?
2012-11-06 13:25:11
2012-11-06 13:32:57
2012-11-06 13:33:14
2012-11-06 14:04:08
From: The Killer
anyway tried googling it? are you able to use other programs to do this?
From: mormonman
http://en.wikipedia.org/wiki/HSL_and_HSV#Converting_to_RGB
2012-11-06 14:09:10
From: Kasi
Nope :(
Already had a look at it, was quite confusing :S
2012-11-06 14:14:34
From: mormonman
Well that is the formula, here it is in simba's source: https://github.com/MerlijnWajer/Simba/blob/master/Units/MMLCore/colour_conv.pas#L205
As you can see, the integer color is first converted to rgb then to hsl.
2012-11-06 14:52:22
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.