Color

Color Struct

The Color class holds RGBA values that define a color.

Syntax

public struct Color

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Members

See Also: Inherited members from ValueType.

Public Constructors

 
Creates a new color with the supplied values.
 
Creates a new solid color with the supplied values.
 
Creates a new color with the supplied values.

Public Fields

static readonly
Black Color . Black
static readonly
Blue Color . Blue
static readonly
Clear Color . Clear
static readonly
Cyan Color . Cyan
static readonly
Gray Color . Gray
static readonly
Green Color . Green
static readonly
Magenta Color . Magenta
static readonly
Red Color . Red
static readonly
White Color . White
static readonly
Yellow Color . Yellow

Public Properties

 
A float . The alpha component of the color.
 
B float . The blue component of the color.
 
G float . The green component of the color.
 
R float . The red component of the color.

Public Methods

 
Lerp (ref Color, float) : Color
Performs a linear interpolation between two colors.
static
Parse (string) : Color
Parse a Color from a string.
 
ToRGB () : string
Generates a string RGB representation of the color.
 
ToRGBA () : string
Generates a string RGBA representation of the color.
override
ToString () : string
Generates a string representation of the color.
 
ToString (string) : string
Generates a string representation of the color.
static
TryParse (string, out Color) : bool
Attempt to parse a Color from a string

Public Operators

static
Addition (Color, Color) Performs color addition.
static
Division (Color, float) Divides color components by a scalar.
static
Multiply (Color, float) Performs a color scalar multiplication.
static
Multiply (float, Color) Performs a color scalar multiplication.
static
Subtraction (Color, Color) Performs color subtraction.
static
Conversion to Sansar.Color (Implicit) Converts a Mono.Simd.Vector4f to a Color.
static
Conversion to Mono.Simd.Vector4f (Implicit) Converts a Color to a Mono.Simd.Vector4f

Member Details

Color Constructor

Creates a new color with the supplied values.

Syntax

public Color (Mono.Simd.Vector4f v)

Parameters

v
Initializes the color from a Mono.Simd.Vector4f.

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Color Constructor

Creates a new solid color with the supplied values.

Syntax

public Color (float r, float g, float b)

Parameters

r
The red component.
g
The green component.
b
The blue component.

Remarks

The alpha component is set to 1.

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Color Constructor

Creates a new color with the supplied values.

Syntax

public Color (float r, float g, float b, float a)

Parameters

r
The red component.
g
The green component.
b
The blue component.
a
The alpha component.

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

A Property

The alpha component of the color.

Syntax

public float A { get; set; }

Value

Remarks

Alpha is 1 by default.

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

B Property

The blue component of the color.

Syntax

public float B { get; set; }

Value

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Black Field

Black

Syntax

public static readonly Color Black

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Blue Field

Blue

Syntax

public static readonly Color Blue

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Clear Field

Clear

Syntax

public static readonly Color Clear

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Cyan Field

Cyan

Syntax

public static readonly Color Cyan

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

G Property

The green component of the color.

Syntax

public float G { get; set; }

Value

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Gray Field

Gray

Syntax

public static readonly Color Gray

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Green Field

Green

Syntax

public static readonly Color Green

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Lerp Method

Performs a linear interpolation between two colors.

Syntax

public Color Lerp (ref Color c, float amount)

Parameters

c
The second color.
amount
Value from [0..1] indicating the weight for the second color.

Returns

A color that is linearly interpolated between the two sources.

Remarks

a + (c-a) * amount.

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Magenta Field

Magenta

Syntax

public static readonly Color Magenta

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

op_Addition Method

Performs color addition.

Syntax

public static Color operator+ (Color a, Color b)

Parameters

a
The first Color.
b
The second Color.

Returns

A new color that is the sum of the arguments.

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

op_Division Method

Divides color components by a scalar.

Syntax

public static Color operator/ (Color c, float s)

Parameters

c
The color.
s
The scalar.

Returns

Returns a new color with value [c.R/s, c.G/s, c.B/s, c.A/s]

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Conversion Method

Converts a Mono.Simd.Vector4f to a Color.

Syntax

public static implicit operator Color (Mono.Simd.Vector4f v)

Parameters

v
Vector to convert

Returns

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Conversion Method

Converts a Color to a Mono.Simd.Vector4f

Syntax

public static implicit operator Mono.Simd.Vector4f (Color c)

Parameters

c
Color to convert

Returns

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

op_Multiply Method

Performs a color scalar multiplication.

Syntax

public static Color operator* (Color c, float s)

Parameters

c
The color.
s
The scalar.

Returns

Returns a new color with value [c.R*s, c.G*s, c.B*s, c.A*s]

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

op_Multiply Method

Performs a color scalar multiplication.

Syntax

public static Color operator* (float s, Color c)

Parameters

s
The scalar.
c
The color.

Returns

Returns a new color with value [s*c.R, s*c.G, s*c.B, s*c.A]

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

op_Subtraction Method

Performs color subtraction.

Syntax

public static Color operator- (Color a, Color b)

Parameters

a
The first Color.
b
The second Color.

Returns

A new color that is the difference of the arguments.

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Parse Method

Parse a Color from a string.

Syntax

public static Color Parse (string colorString)

Parameters

colorString
A string of the format (R,G,B) or (R,G,B,A)

Returns

The Color parsed from the string.

Exceptions

Type Reason
ArgumentException If colorString is null.
FormatException If the string is not a valid color or its components are not valid floats.

Remarks

 

Example

C# Example
Color myColor = Color.Parse("(0.5,1.0,0.8)");

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

R Property

The red component of the color.

Syntax

public float R { get; set; }

Value

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Red Field

Red

Syntax

public static readonly Color Red

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

ToRGB Method

Generates a string RGB representation of the color.

Syntax

public string ToRGB ()

Returns

The RGB color as a string.

Remarks

RGB values are based on a scale from 0 to 255.

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

ToRGBA Method

Generates a string RGBA representation of the color.

Syntax

public string ToRGBA ()

Returns

The RGBA color as a string.

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

ToString Method

Generates a string representation of the color.

Syntax

public override string ToString ()

Returns

The color as a string.

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

ToString Method

Generates a string representation of the color.

Syntax

public string ToString (string format)

Parameters

format
Format to use for each of the coordinates.

Returns

The color as a string.

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

TryParse Method

Attempt to parse a Color from a string

Syntax

public static bool TryParse (string colorString, out Color color)

Parameters

colorString
A string of the format (R,G,B) or (R,G,B,A)
color
The color that will be set if colorString represents a valid color.

Returns

True if successfully parsed a color, false if not.

Remarks

 

Example

C# Example
Color myColor;
            if (Color.Parse("(0.5,1.0,0.8)", out myColor)
            {
                // myColor is set
            }

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

White Field

White

Syntax

public static readonly Color White

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Yellow Field

Yellow

Syntax

public static readonly Color Yellow

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0


Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Article is closed for comments.