36 get {
return this._h; }
45 get {
return this._s; }
54 get {
return this._l; }
57 public HslColor(
float hue,
float saturation,
float lightness)
59 if (hue < 0f || 360f <= hue)
61 throw new ArgumentException(
"hueは0以上360未満の値です。",
"hue");
63 if (saturation < 0f || 1f < saturation)
65 throw new ArgumentException(
"saturationは0以上1以下の値です。",
"saturation");
67 if (lightness < 0f || 1f < lightness)
69 throw new ArgumentException(
"lightnessは0以上1以下の値です。",
"lightness");
84 float r = (float)rgb.R / 255f;
85 float g = (
float)rgb.G / 255f;
86 float b = (float)rgb.B / 255f;
88 float max = Math.Max(r, Math.Max(g, b));
89 float min = Math.Min(r, Math.Min(g, b));
91 float lightness = (max + min) / 2f;
93 float hue, saturation;
110 hue = (b - r) / c + 2f;
114 hue = (r - g) / c + 4f;
123 if (lightness < 0.5f)
125 saturation = c / (max + min);
129 saturation = c / (2f - max - min);
133 return new HslColor(hue, saturation, lightness);
155 float h = hsl.
H / 60f;
156 int i = (int)Math.Floor(h);
166 c = 2f * s * (1f - l);
168 float m = l - c / 2f;
174 q = l + c * (f - 0.5f);
178 q = l - c * (f - 0.5f);
214 throw new ArgumentException(
"色相の値が不正です。",
"hsl");
218 return Color.FromArgb(
219 (
int)Math.Round(r1 * 255f),
220 (int)Math.Round(g1 * 255f),
221 (int)Math.Round(b1 * 255f));