122 public float this[
int index]
137 throw new IndexOutOfRangeException(
"Invalid Color index(" + index +
")!");
157 throw new IndexOutOfRangeException(
"Invalid Color index(" + index +
")!");
197 return String.Format(
"RGBA({0:F3}, {1:F3}, {2:F3}, {3:F3})",
r,
g,
b,
a);
206 return String.Format(
"RGBA({0}, {1}, {2}, {3})",
r.ToString(),
g.ToString(),
b.ToString(),
a.ToString());
209 public override bool Equals(
object other)
211 if (!(other is
Color))
220 return r.Equals(other.
r) &&
g.Equals(other.
g) &&
b.Equals(other.
b) &&
a.Equals(other.
a);
225 return new Color(
a.r +
b.r,
a.g +
b.g,
a.b +
b.b,
a.a +
b.a);
230 return new Color(
a.r -
b.r,
a.g -
b.g,
a.b -
b.b,
a.a -
b.a);
235 return new Color(
a.r *
b.r,
a.g *
b.g,
a.b *
b.b,
a.a *
b.a);
260 return !(lhs == rhs);
282 return new Color(
a.r + (
b.r -
a.r) * t,
a.g + (
b.g -
a.g) * t,
a.b + (
b.b -
a.b) * t,
a.a + (
b.a -
a.a) * t);
293 return new Color(
a.r + (
b.r -
a.r) * t,
a.g + (
b.g -
a.g) * t,
a.b + (
b.b -
a.b) * t,
a.a + (
b.a -
a.a) * t);
296 public static void RGBToHSV(
Color rgbColor, out
float H, out
float S, out
float V)
298 if (rgbColor.
b > rgbColor.
g && rgbColor.
b > rgbColor.
r)
300 RGBToHSVHelper(4f, rgbColor.
b, rgbColor.
r, rgbColor.
g, out
H, out
S, out
V);
302 else if (rgbColor.
g > rgbColor.
r)
304 RGBToHSVHelper(2f, rgbColor.
g, rgbColor.
b, rgbColor.
r, out
H, out
S, out
V);
308 RGBToHSVHelper(0f, rgbColor.
r, rgbColor.
g, rgbColor.
b, out
H, out
S, out
V);
312 private static void RGBToHSVHelper(
float offset,
float dominantcolor,
float colorone,
float colortwo, out
float H, out
float S, out
float V)
318 num = ((!(colorone > colortwo)) ? colorone : colortwo);
319 float num2 =
V - num;
323 H = offset + (colorone - colortwo) / num2;
328 H = offset + (colorone - colortwo);
390 float num3 = num - (float)num2;
391 float num4 =
V * (1f -
S);
392 float num5 =
V * (1f -
S * num3);
393 float num6 =
V * (1f -
S * (1f - num3));
449 return base.GetHashCode();
static float Floor(float f)
static float Clamp(float value, float min, float max)
static float Clamp01(float value)
static Color HSVToRGB(float H, float S, float V, bool hdr)
static Color operator+(Color a, Color b)
static Color LerpUnclamped(Color a, Color b, float t)
override string ToString()
static bool operator!=(Color lhs, Color rhs)
static Color operator/(Color a, float b)
static Color HSVToRGB(float H, float S, float V)
override int GetHashCode()
Color(float r, float g, float b)
static bool operator==(Color lhs, Color rhs)
static Color operator*(Color a, Color b)
static Color operator-(Color a, Color b)
string ToString(string format)
override bool Equals(object other)
Color(float r, float g, float b, float a)
static void RGBToHSV(Color rgbColor, out float H, out float S, out float V)
static Color Lerp(Color a, Color b, float t)