wiki.sine.space | sinespace

Scripting/SColor

From wiki.sine.space
Revision as of 09:05, 24 December 2020 by Edisonwu (Talk | contribs)

Jump to: navigation, search

The SColor class represents RGBA colors.

Members

New

SColor New {float r, float g, float b, float a}

Create a color by red, green, blue and alpha parameters.

--create a cube and set a new material.

--add ScriptingRuntime.
local mat=Space.Host.ExecutingObject.Renderer.Material;
mat.SetColor("_Color",Color.New(0,0,1,1))

--the cube will turn to blue.


FromHex

SColor FromHex {string hex}

Create a color by Hex value.

--create a cube and set a new material.

--add ScriptingRuntime.
local mat=Space.Host.ExecutingObject.Renderer.Material;
mat.SetColor("_Color",Color.FromHex("FF0000"))

--the cube will turn to red.


ToHex

string ToHex ();

Return the Hex value of the color.

Space.Log(Color.Red.ToHex())
--print "FF0000".


Lerp

SColor Lerp (SColor b, float t);

Linearly interpolates between current color and b by t.

--create a cube and set a new material.

--add ScriptingRuntime.
local mat=Space.Host.ExecutingObject.Renderer.Material
function ChangeColor()
    mat.SetColor("_Color",Color.Red.Lerp(Color.Blue,Space.Math.PingPong(Space.Time,1)))
end

Space.Host.ExecutingObject.OnUpdate(ChangeColor)


Equals

bool Equals (SColor other);

Returns true if colors are same.

local colorR=Color.New(1,0,0,1)

Space.Log(colorR.Equals(Color.Red))

--Print "true".


ToString

string ToString (SColor other);

Returns the RGBA value of the current color.

Space.Log(Color.Red.ToString())
--print "[1,0,0,1]".



Properties

Black

SColor Black {get;}

Solid black. RGBA is (0, 0, 0, 1).

--create a cube and set a new material.

--add ScriptingRuntime.
local mat=Space.Host.ExecutingObject.Renderer.Material;
mat.SetColor("_Color",Color.Black)

--the cube will turn to black.


White

SColor White {get;}

Solid White. RGBA is (1, 1, 1, 1).

--create a cube and set a new material.

--add ScriptingRuntime.
local mat=Space.Host.ExecutingObject.Renderer.Material;
mat.SetColor("_Color",Color.White)

--the cube will turn to white.


Red

SColor Red {get;}

Solid Red. RGBA is (1, 0, 0, 1).

--create a cube and set a new material.

--add ScriptingRuntime.
local mat=Space.Host.ExecutingObject.Renderer.Material;
mat.SetColor("_Color",Color.Red)

--the cube will turn to red.


Blue

SColor Blue {get;}

Solid Blue. RGBA is (0, 0, 1, 1).

--create a cube and set a new material.

--add ScriptingRuntime.
local mat=Space.Host.ExecutingObject.Renderer.Material;
mat.SetColor("_Color",Color.Blue)

--the cube will turn to blue.


Green

SColor Green {get;}

Solid Green. RGBA is (0, 1, 0, 1).

--create a cube and set a new material.

--add ScriptingRuntime.
local mat=Space.Host.ExecutingObject.Renderer.Material;
mat.SetColor("_Color",Color.Green)

--the cube will turn to green.


Yellow

SColor Yellow {get;}

Yellow. RGBA is (1, 0.92, 0.016, 1).

--create a cube and set a new material.

--add ScriptingRuntime.
local mat=Space.Host.ExecutingObject.Renderer.Material;
mat.SetColor("_Color",Color.Yellow)

--the cube will turn to yellow.