wiki.sine.space | sinespace

Difference between revisions of "Scripting/SColor"

From wiki.sine.space
Jump to: navigation, search
(Created page with "The SColor class represents RGBA colors. =Members= {{ScriptFunction|static SColor|New|{float r, float g, float b, float a}|Create a color by red, green, blue and alpha parame...")
 
Line 2: Line 2:
  
 
=Members=
 
=Members=
{{ScriptFunction|static SColor|New|{float r, float g, float b, float a}|Create a color by red, green, blue and alpha parameters.|5=
+
{{ScriptFunction|SColor|New|{float r, float g, float b, float a}|Create a color by red, green, blue and alpha parameters.|5=
 
''--create a cube and set a new material.''<br>
 
''--create a cube and set a new material.''<br>
 
''--add ScriptingRuntime.''<br>
 
''--add ScriptingRuntime.''<br>
Line 10: Line 10:
 
}}
 
}}
  
{{ScriptFunction|static SColor|FromHex|{string hex}|Create a color by Hex value.|5=
+
{{ScriptFunction|SColor|FromHex|{string hex}|Create a color by Hex value.|5=
 
''--create a cube and set a new material.''<br>
 
''--create a cube and set a new material.''<br>
 
''--add ScriptingRuntime.''<br>
 
''--add ScriptingRuntime.''<br>
Line 39: Line 39:
 
}}
 
}}
  
{{ScriptFunction|override string|ToString|(SColor other);|Returns the RGBA value of the current color.|5=
+
{{ScriptFunction|string|ToString|(SColor other);|Returns the RGBA value of the current color.|5=
 
Space.Log(Color.Red.ToString())<br>
 
Space.Log(Color.Red.ToString())<br>
 
''--print "[1,0,0,1]".''
 
''--print "[1,0,0,1]".''

Revision as of 09:05, 24 December 2020

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.