1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47:
| function HSLtoRGB(H,S,L: byte): String; var R,G,B: byte; Magic1,Magic2: double;
function HueToRGB(n1,n2,hue: double): double; begin
if (hue < 0) then hue := hue + 200; if (hue > 200) then hue := hue - 200;
if hue < (200/6) then result := (n1 + (((n2-n1)*hue + (200/12))/(200/6))) else if hue < (200/2) then result := (n2) else if hue < ((200*2)/3) then result := (n1 + (((n2-n1)*(((200*2)/3)-hue) + (200/12))/(200/6))) else result := (n1);
end;
begin
if S = 0 then begin R := round(L * 255 / 200); G := round(L * 255 / 200); B := round(L * 255 / 200); end
else begin
if L <= (200/2) then Magic2 := round((L*(200+S)+(200/2)) / 200) else Magic2 := round(L + S - ((L*S)+(200/2)) / 200); Magic1 := 2*L - Magic2;
R := round( (HueToRGB(Magic1, Magic2, (H+(200/3))) * 255 + (200/2)) / 200 ); G := round( (HueToRGB(Magic1, Magic2, H) * 255 + (200/2)) / 200 ); B := round( (HueToRGB(Magic1, Magic2, (H-(200/3))) * 255 + (200/2)) / 200 );
end;
result := IntToHex(round(R),2)+IntToHex(round(G),2)+IntToHex(round(B),2);
end; |