18.07.2012, 10:58
(
Последний раз редактировалось xX_Simon_Xx; 18.07.2012 в 18:50.
)
PHP код:
public RGBColor HSBToRGB(HSBColor hsb)
{
RGBColor functionReturnValue = default(RGBColor);
double maxRGB = 0;
double Delta = 0;
double h = 0;
double s = 0;
double b = 0;
h = hsb.Hue / 60;
s = hsb.Saturation * 255 / 100;
b = hsb.Brightness * 255 / 100;
maxRGB = b;
if (s == 0) {
functionReturnValue.Red = 0;
functionReturnValue.Green = 0;
functionReturnValue.Blue = 0;
} else {
Delta = s * maxRGB / 255;
if (h > 3) {
functionReturnValue.Blue = Convert.ToByte(Round(maxRGB));
if (h > 4) {
functionReturnValue.Green = Convert.ToByte(Round(maxRGB - Delta));
functionReturnValue.Red = Convert.ToByte(Round((h - 4) * Delta)) + functionReturnValue.Green;
} else {
functionReturnValue.Red = Convert.ToByte(Round(maxRGB - Delta));
functionReturnValue.Green = Convert.ToByte(functionReturnValue.Red - Round((h - 4) * Delta));
}
} else {
if (h > 1) {
functionReturnValue.Green = Convert.ToByte(Round(maxRGB));
if (h > 2) {
functionReturnValue.Red = Convert.ToByte(Round(maxRGB - Delta));
functionReturnValue.Blue = Convert.ToByte(Round((h - 2) * Delta)) + functionReturnValue.Red;
} else {
functionReturnValue.Blue = Convert.ToByte(Round(maxRGB - Delta));
functionReturnValue.Red = Convert.ToByte(functionReturnValue.Blue - Round((h - 2) * Delta));
}
} else {
if (h > -1) {
functionReturnValue.Red = Convert.ToByte(Round(maxRGB));
if (h > 0) {
functionReturnValue.Blue = Convert.ToByte(Round(maxRGB - Delta));
functionReturnValue.Green = Convert.ToByte(Round(h * Delta)) + functionReturnValue.Blue;
} else {
functionReturnValue.Green = Convert.ToByte(Round(maxRGB - Delta));
functionReturnValue.Blue = Convert.ToByte(functionReturnValue.Green - Round(h * Delta));
}
}
}
}
}
return functionReturnValue;
}
