CColorRef:delete

CColorRef:new


The new method constructs a new instance of a CColorRef object. The CColorRef class includes 3 data members for R, G, and B color intensities. Three different constructor overloads are available to create a new CColorRef and initialize the data members.

Syntax

C = CColorRef:new()

    Creates a new object with color initialized to (0,0,0).

C = CColorRef:new( CColorRef2 )

    This is a copy constructor. It creates a new CColorRef C initialized to the color of the CColorRef2 argument.

C = CColorRef:new( R, G, B )

    Creates a new CColorRef with members initialized to the R, G, and B values.

Remarks

Three overloads are provided for this method. They create a default CColorRef, a copy of a CColorRef, or an initialized CColorRef. If you pass something other than nil, a CColorRef, or data member values—such as a string—the default constructor is used.

Example

The following script fragment computes the equivalent gray intensity using 2 different constructors:

 

A = CColorRef(255,140,5)

-- create CColorRef A with values

B = CColorRef:new( A )

-- copy A to a new CColorRef B

n = A:ToGray(B)

-- complement the color

Printf("%d,%d,%d -> %.2lf", A.R,A.G,A.B,n)

-- result: 255,140,5 -> 158.19

Printf("%d,%d,%d -> %.2lf", B.R,B.G,B.B,n)

-- result: 255,140,5 -> 158.19

Related Topics

CColorRef, delete