Wiki

Clone wiki

Core / color

Back to Beyond the Codea in-app reference


FunctionIconType-Small.png color() function

Introduction

Codea's built-in reference documents most of the color() function. The function returns a userdata value that is a vector in four dimensions, used to represent red, green, blue and alpha (opacity) values.

Setting and getting individual coordinates

Indexing can be used to set and get individual co-ordinates, either by (r, g, b, a) or by ordinal number or by other letters - (x, y, z, w), as summarised in the table below:

Co-ordinateIndex schemeIndex schemeIndex scheme
Firstc1[1]c1.x or c1["x"]c1.r or c1["r"]
Secondc1[2]c1.y or c1["y"]c1.g or c1["g"]
Thirdc1[3]c1.z or c1["z"]c1.b or c1["b"]
Fourthc1[4]c1.w or c1["w"]c1.a or c1["a"]

Each co-ordinate can be set to any number value (and is not constrained, for example, to the range 0 to 255). The graphical color picking in Codea's Editor tolerates this.

Operators

From version 1.4.3 of Codea, like vec4(), the result of the color() function supports operators, such as the == operator. For example:

print(color(0, 0, 0, 0) == color(0, 0, 0, 0)) -- Output is 'true'
print(vec4(0, 0, 0, 0) == vec4(0, 0, 0, 0))   -- Output is 'true'

Functions

The result supports tostring() to produce nicely-formatted output. Consequently, print() also generates nicely-formatted output.

Updated