Struct Color3
- Namespace
- Stride.Core.Mathematics
- Assembly
- Stride.Core.Mathematics.dll
Represents a color in the form of rgb.
[DataContract("Color3")]
[DataStyle(DataStyle.Compact)]
public struct Color3 : IEquatable<Color3>, IFormattable
- Implements
Constructors
Color3(Vector3)
Initializes a new instance of the Color3 struct.
public Color3(Vector3 value)
Parameters
value
Vector3The red, green, and blue components of the color.
Color3(int)
Initializes a new instance of the Color3 struct.
public Color3(int rgb)
Parameters
rgb
intA packed integer containing all three color components. The alpha component is ignored.
Color3(float)
Initializes a new instance of the Color3 struct.
public Color3(float value)
Parameters
value
floatThe value that will be assigned to all components.
Color3(float, float, float)
Initializes a new instance of the Color3 struct.
public Color3(float red, float green, float blue)
Parameters
red
floatThe red component of the color.
green
floatThe green component of the color.
blue
floatThe blue component of the color.
Color3(float[])
Initializes a new instance of the Color3 struct.
public Color3(float[] values)
Parameters
values
float[]The values to assign to the red, green, and blue components of the color. This must be an array with three elements.
Exceptions
- ArgumentNullException
Thrown when
values
isnull
.- ArgumentOutOfRangeException
Thrown when
values
contains more or less than four elements.
Color3(uint)
Initializes a new instance of the Color3 struct.
public Color3(uint rgb)
Parameters
rgb
uintA packed unsigned integer containing all three color components. The alpha component is ignored.
Fields
B
The blue component of the color.
[DataMember(2)]
public float B
Field Value
G
The green component of the color.
[DataMember(1)]
public float G
Field Value
R
The red component of the color.
[DataMember(0)]
public float R
Field Value
Properties
this[int]
Gets or sets the component at the specified index.
public float this[int index] { get; set; }
Parameters
index
intThe index of the component to access. Use 0 for the red component, 1 for the green component, and 2 for the blue component.
Property Value
- float
The value of the red, green, or blue component, depending on the index.
Exceptions
- ArgumentOutOfRangeException
Thrown when the
index
is out of the range [0, 2].
Methods
Add(Color3, Color3)
Adds two colors.
public static Color3 Add(Color3 left, Color3 right)
Parameters
Returns
- Color3
The sum of the two colors.
Add(ref readonly Color3, ref readonly Color3, out Color3)
Adds two colors.
public static void Add(ref readonly Color3 left, ref readonly Color3 right, out Color3 result)
Parameters
left
Color3The first color to add.
right
Color3The second color to add.
result
Color3When the method completes, completes the sum of the two colors.
AdjustContrast(Color3, float)
Adjusts the contrast of a color.
public static Color3 AdjustContrast(Color3 value, float contrast)
Parameters
value
Color3The color whose contrast is to be adjusted.
contrast
floatThe amount by which to adjust the contrast.
Returns
- Color3
The adjusted color.
AdjustContrast(ref readonly Color3, float, out Color3)
Adjusts the contrast of a color.
public static void AdjustContrast(ref readonly Color3 value, float contrast, out Color3 result)
Parameters
value
Color3The color whose contrast is to be adjusted.
contrast
floatThe amount by which to adjust the contrast.
result
Color3When the method completes, contains the adjusted color.
AdjustSaturation(Color3, float)
Adjusts the saturation of a color.
public static Color3 AdjustSaturation(Color3 value, float saturation)
Parameters
value
Color3The color whose saturation is to be adjusted.
saturation
floatThe amount by which to adjust the saturation.
Returns
- Color3
The adjusted color.
AdjustSaturation(ref readonly Color3, float, out Color3)
Adjusts the saturation of a color.
public static void AdjustSaturation(ref readonly Color3 value, float saturation, out Color3 result)
Parameters
value
Color3The color whose saturation is to be adjusted.
saturation
floatThe amount by which to adjust the saturation.
result
Color3When the method completes, contains the adjusted color.
Clamp(Color3, Color3, Color3)
Restricts a value to be within a specified range.
public static Color3 Clamp(Color3 value, Color3 min, Color3 max)
Parameters
Returns
- Color3
The clamped value.
Clamp(ref readonly Color3, ref readonly Color3, ref readonly Color3, out Color3)
Restricts a value to be within a specified range.
public static void Clamp(ref readonly Color3 value, ref readonly Color3 min, ref readonly Color3 max, out Color3 result)
Parameters
value
Color3The value to clamp.
min
Color3The minimum value.
max
Color3The maximum value.
result
Color3When the method completes, contains the clamped value.
Deconstruct(out float, out float, out float)
Deconstructs the vector's components into named variables.
public void Deconstruct(out float r, out float g, out float b)
Parameters
Equals(Color3)
Determines whether the specified Color3 is equal to this instance.
public bool Equals(Color3 other)
Parameters
Returns
Equals(object)
Determines whether the specified object is equal to this instance.
public override bool Equals(object value)
Parameters
Returns
GetHashCode()
Returns a hash code for this instance.
public override int GetHashCode()
Returns
- int
A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
Lerp(Color3, Color3, float)
Performs a linear interpolation between two colors.
public static Color3 Lerp(Color3 start, Color3 end, float amount)
Parameters
start
Color3Start color.
end
Color3End color.
amount
floatValue between 0 and 1 indicating the weight of
end
.
Returns
- Color3
The linear interpolation of the two colors.
Remarks
This method performs the linear interpolation based on the following formula.
start + (end - start) * amount
Passing amount
a value of 0 will cause start
to be returned; a value of 1 will cause end
to be returned.
Lerp(ref readonly Color3, ref readonly Color3, float, out Color3)
Performs a linear interpolation between two colors.
public static void Lerp(ref readonly Color3 start, ref readonly Color3 end, float amount, out Color3 result)
Parameters
start
Color3Start color.
end
Color3End color.
amount
floatValue between 0 and 1 indicating the weight of
end
.result
Color3When the method completes, contains the linear interpolation of the two colors.
Remarks
This method performs the linear interpolation based on the following formula.
start + (end - start) * amount
Passing amount
a value of 0 will cause start
to be returned; a value of 1 will cause end
to be returned.
Max(Color3, Color3)
Returns a color containing the largest components of the specified colorss.
public static Color3 Max(Color3 left, Color3 right)
Parameters
Returns
- Color3
A color containing the largest components of the source colors.
Max(ref readonly Color3, ref readonly Color3, out Color3)
Returns a color containing the smallest components of the specified colorss.
public static void Max(ref readonly Color3 left, ref readonly Color3 right, out Color3 result)
Parameters
left
Color3The first source color.
right
Color3The second source color.
result
Color3When the method completes, contains an new color composed of the largest components of the source colorss.
Min(Color3, Color3)
Returns a color containing the smallest components of the specified colors.
public static Color3 Min(Color3 left, Color3 right)
Parameters
Returns
- Color3
A color containing the smallest components of the source colors.
Min(ref readonly Color3, ref readonly Color3, out Color3)
Returns a color containing the smallest components of the specified colors.
public static void Min(ref readonly Color3 left, ref readonly Color3 right, out Color3 result)
Parameters
left
Color3The first source color.
right
Color3The second source color.
result
Color3When the method completes, contains an new color composed of the smallest components of the source colors.
Modulate(Color3, Color3)
Modulates two colors.
public static Color3 Modulate(Color3 left, Color3 right)
Parameters
Returns
- Color3
The modulated color.
Modulate(ref readonly Color3, ref readonly Color3, out Color3)
Modulates two colors.
public static void Modulate(ref readonly Color3 left, ref readonly Color3 right, out Color3 result)
Parameters
left
Color3The first color to modulate.
right
Color3The second color to modulate.
result
Color3When the method completes, contains the modulated color.
Negate(Color3)
Negates a color.
public static Color3 Negate(Color3 value)
Parameters
value
Color3The color to negate.
Returns
- Color3
The negated color.
Negate(ref readonly Color3, out Color3)
Negates a color.
public static void Negate(ref readonly Color3 value, out Color3 result)
Parameters
value
Color3The color to negate.
result
Color3When the method completes, contains the negated color.
Pow(float)
Raises the exponent for each components.
public void Pow(float exponent)
Parameters
exponent
floatThe exponent.
Scale(Color3, float)
Scales a color.
public static Color3 Scale(Color3 value, float scale)
Parameters
Returns
- Color3
The scaled color.
Scale(ref readonly Color3, float, out Color3)
Scales a color.
public static void Scale(ref readonly Color3 value, float scale, out Color3 result)
Parameters
value
Color3The color to scale.
scale
floatThe amount by which to scale.
result
Color3When the method completes, contains the scaled color.
SmoothStep(Color3, Color3, float)
Performs a cubic interpolation between two colors.
public static Color3 SmoothStep(Color3 start, Color3 end, float amount)
Parameters
start
Color3Start color.
end
Color3End color.
amount
floatValue between 0 and 1 indicating the weight of
end
.
Returns
- Color3
The cubic interpolation of the two colors.
SmoothStep(ref readonly Color3, ref readonly Color3, float, out Color3)
Performs a cubic interpolation between two colors.
public static void SmoothStep(ref readonly Color3 start, ref readonly Color3 end, float amount, out Color3 result)
Parameters
start
Color3Start color.
end
Color3End color.
amount
floatValue between 0 and 1 indicating the weight of
end
.result
Color3When the method completes, contains the cubic interpolation of the two colors.
Subtract(Color3, Color3)
Subtracts two colors.
public static Color3 Subtract(Color3 left, Color3 right)
Parameters
Returns
- Color3
The difference of the two colors.
Subtract(ref readonly Color3, ref readonly Color3, out Color3)
Subtracts two colors.
public static void Subtract(ref readonly Color3 left, ref readonly Color3 right, out Color3 result)
Parameters
left
Color3The first color to subtract.
right
Color3The second color to subtract.
result
Color3WHen the method completes, contains the difference of the two colors.
ToArray()
Creates an array containing the elements of the color.
public float[] ToArray()
Returns
- float[]
A three-element array containing the components of the color.
ToColor4()
Convert this color to an equivalent Color4 with an opaque alpha.
public Color4 ToColor4()
Returns
ToLinear()
Converts this color from sRGB space to linear space.
public Color3 ToLinear()
Returns
- Color3
Color3.
ToRgb()
Converts the color into a packed integer.
public int ToRgb()
Returns
- int
A packed integer containing all three color components. The alpha channel is set to 255.
ToSRgb()
Converts this color from linear space to sRGB space.
public Color3 ToSRgb()
Returns
- Color3
A color3 in sRGB space.
ToString()
Returns a string that represents this instance.
public override string ToString()
Returns
ToString(IFormatProvider)
Returns a string that represents this instance.
public string ToString(IFormatProvider formatProvider)
Parameters
formatProvider
IFormatProviderThe format provider.
Returns
ToString(string)
Returns a string that represents this instance.
public string ToString(string format)
Parameters
format
stringThe format.
Returns
ToString(string, IFormatProvider)
Returns a string that represents this instance.
public string ToString(string format, IFormatProvider formatProvider)
Parameters
format
stringThe format.
formatProvider
IFormatProviderThe format provider.
Returns
ToVector3()
Converts the color into a three component vector.
public Vector3 ToVector3()
Returns
- Vector3
A three component vector containing the red, green, and blue components of the color.
Operators
operator +(Color3, Color3)
Adds two colors.
public static Color3 operator +(Color3 left, Color3 right)
Parameters
Returns
- Color3
The sum of the two colors.
operator ==(Color3, Color3)
Tests for equality between two objects.
public static bool operator ==(Color3 left, Color3 right)
Parameters
Returns
- bool
true
ifleft
has the same value asright
; otherwise,false
.
explicit operator Color4(Color3)
public static explicit operator Color4(Color3 value)
Parameters
value
Color3The value.
Returns
- Color4
The result of the conversion.
explicit operator Vector3(Color3)
public static explicit operator Vector3(Color3 value)
Parameters
value
Color3The value.
Returns
- Vector3
The result of the conversion.
explicit operator Color3(Vector3)
public static explicit operator Color3(Vector3 value)
Parameters
value
Vector3The value.
Returns
- Color3
The result of the conversion.
explicit operator Color3(int)
public static explicit operator Color3(int value)
Parameters
value
intThe value.
Returns
- Color3
The result of the conversion.
operator !=(Color3, Color3)
Tests for inequality between two objects.
public static bool operator !=(Color3 left, Color3 right)
Parameters
Returns
- bool
true
ifleft
has a different value thanright
; otherwise,false
.
operator *(Color3, Color3)
Modulates two colors.
public static Color3 operator *(Color3 left, Color3 right)
Parameters
Returns
- Color3
The modulated color.
operator *(Color3, float)
Scales a color.
public static Color3 operator *(Color3 value, float scale)
Parameters
Returns
- Color3
The scaled color.
operator *(float, Color3)
Scales a color.
public static Color3 operator *(float scale, Color3 value)
Parameters
Returns
- Color3
The scaled color.
operator -(Color3, Color3)
Subtracts two colors.
public static Color3 operator -(Color3 left, Color3 right)
Parameters
Returns
- Color3
The difference of the two colors.
operator -(Color3)
Negates a color.
public static Color3 operator -(Color3 value)
Parameters
value
Color3The color to negate.
Returns
- Color3
A negated color.
operator +(Color3)
Assert a color (return it unchanged).
public static Color3 operator +(Color3 value)
Parameters
value
Color3The color to assert (unchange).
Returns
- Color3
The asserted (unchanged) color.