TouchOSC

Next generation modular control surface
TouchOSC Manual

Script · Objects · Color


A color object native to TouchOSC. Will be returned and can be passed anywhere a color is required. Color components are stored as floating point values ranging from 0.0 to 1.0.



Fields

 

color.r

The red component of the color.

 

color.g

The green component of the color.

 

color.b

The blue component of the color.

 

color.a

The alpha component of the color.

 


Constructor Functions

 

function Color()                               -- [1]
function Color(color)                          -- [2]
function Color(number)                         -- [3]
function Color(number, number)                 -- [4]
function Color(number, number, number)         -- [5]
function Color(number, number, number, number) -- [6]

Returns a new color object with

  1. all components initialized with 0.0.
  2. all components copied from another Color object.
  3. all components initialized with number.
  4. rgb components initialized with the first number, the a component initialized with the second number.
  5. rgb components initialized with the three numbers, the a component initialized with 1.0
  6. rgba components initialized with the four numbers provided.

 


Static functions

 

function Color.toHexString(color)


-- example
local redColor = Color(1,0,0)
print(Color.toHexString(redColor))
> FF0000FF

Returns a hexadecimal string representation of the color in the format RRGGBBAA.

 

function Color.fromHexString(string)


-- example
local red = Color.fromHexString('FF0000FF')
local blue = cColor.fromHexString('0000FF')
local grayAlpha = Color.fromHexString('FF80');
local gray = Color.fromHexString('80');

Returns a color object created from the hexadecimal string representation. The string can be in one of the following formats: RRGGBBAA, RRGGBB, GGAA, GG, with the latter two forms creating a grayscale color from the GG value.

 


Operators

 

-- multiplication
color * color
color * number

-- division
color / color
color / number

-- addition
color + color
color + number

-- subtraction
color - color
color - number

All operators operate component-wise and return a new color object.

 


Cookie Policy

We use cookies to deliver website content. By continuing without changing your preferences, you agree to our use of cookies.