Skip to content

Get Sansar

Script API

Color

Where: Client
More page actions

For the complete documentation index, see llms.txt. This page is also available as Markdown.

Struct Namespace Sansar

The Color class holds RGBA values that define a color.

public struct Color

Members at a glance

KindMembers
ConstructorsColor
FieldsBlack · Blue · Clear · Cyan · Gray · Green · Magenta · Red · White · Yellow
PropertiesA · B · G · R
MethodsLerp · Parse · ToRGB · ToRGBA · ToString · TryParse
Operatorsop_Addition · op_Division · op_Implicit · op_Multiply · op_Subtraction

Constructors

Color

public Color(Mono.Simd.Vector4f v)

Creates a new color with the supplied values.

ParameterTypeDescription
vMono.Simd.Vector4fInitializes the color from a Vector4f.
public Color(float r, float g, float b)

Creates a new solid color with the supplied values.

ParameterTypeDescription
rfloatThe red component.
gfloatThe green component.
bfloatThe blue component.
Remarks

The alpha component is set to 1.

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

Creates a new color with the supplied values.

ParameterTypeDescription
rfloatThe red component.
gfloatThe green component.
bfloatThe blue component.
afloatThe alpha component.

Fields

Black

public static readonly Color Black

Black

Blue

public static readonly Color Blue

Blue

Clear

public static readonly Color Clear

Clear

Cyan

public static readonly Color Cyan

Cyan

Gray

public static readonly Color Gray

Gray

Green

public static readonly Color Green

Green

Magenta

public static readonly Color Magenta

Magenta

Red

public static readonly Color Red

Red

White

public static readonly Color White

White

Yellow

public static readonly Color Yellow

Yellow

Properties

A

public float A { get; set; }

The alpha component of the color.

Remarks

Alpha is 1 by default.

B

public float B { get; set; }

The blue component of the color.

G

public float G { get; set; }

The green component of the color.

R

public float R { get; set; }

The red component of the color.

Methods

Lerp

public Color Lerp(ref Color c, float amount)

Performs a linear interpolation between two colors.

ParameterTypeDescription
cColorThe second color.
amountfloatValue from [0..1] indicating the weight for the second color.

Returns: Color — A color that is linearly interpolated between the two sources.

Remarks

This method performs the linear interpolation as:

a + (c-a) * amount.

An amount value of 0 returns the original color, and 1.0 returns color c.

Parse

public static Color Parse(string colorString)

Parse a Color from a string.

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

Returns: Color — The Color parsed from the string.

Throws ArgumentException: If colorString is null.

Throws FormatException: If the string is not a valid color or its components are not valid floats.

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

ToRGB

public string ToRGB()

Generates a string RGB representation of the color.

Returns: string — The RGB color as a string.

Remarks

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

ToRGBA

public string ToRGBA()

Generates a string RGBA representation of the color.

Returns: string — The RGBA color as a string.

ToString

public override string ToString()

Generates a string representation of the color.

Returns: string — The color as a string.

public string ToString(string format)

Generates a string representation of the color.

ParameterTypeDescription
formatstringFormat to use for each of the coordinates.

Returns: string — The color as a string.

TryParse

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

Attempt to parse a Color from a string

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

Returns: bool — True if successfully parsed a color, false if not.

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

Operators

op_Addition

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

Performs color addition.

ParameterTypeDescription
aColorThe first Color.
bColorThe second Color.

Returns: Color — A new color that is the sum of the arguments.

op_Division

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

Divides color components by a scalar.

ParameterTypeDescription
cColorThe color.
sfloatThe scalar.

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

op_Implicit

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

Converts a Mono.Simd.Vector4f to a Color.

ParameterTypeDescription
vMono.Simd.Vector4fVector to convert
public static implicit operator Mono.Simd.Vector4f(Color c)

Converts a Color to a Mono.Simd.Vector4f

ParameterTypeDescription
cColorColor to convert

op_Multiply

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

Performs a color scalar multiplication.

ParameterTypeDescription
cColorThe color.
sfloatThe scalar.

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

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

Performs a color scalar multiplication.

ParameterTypeDescription
sfloatThe scalar.
cColorThe color.

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

op_Subtraction

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

Performs color subtraction.

ParameterTypeDescription
aColorThe first Color.
bColorThe second Color.

Returns: Color — A new color that is the difference of the arguments.

Used in examples

Generated from the Sansar 47.10.0 client ScriptApi snapshot.