CColorRef:ToGray


The ToGray method returns the gray equivalent luminance of a color triplet. The conversion is computed using the standard visual response weights (see Visual Response Equivalent Gray).

Syntax

nGray = CColorRef:ToGray()

nGray = CColorRef:ToGray( CColorRef )

nGray = CColorRef:ToGray( R, G, B )

where

    R, G, B are the color components to convert.

    CColorRef is an existing CColorRef object to copy.

    nGray is the gray equivalent of the R, G, B values. On failure, 0 is returned.

  

Three overloads are provided for this method; they compute the gray equivalent for the class members, a CColorRef object, or for 3 explicit color values. If you pass something other than a CColorRef or R, G, B values, such as a string or a number, this method defaults to using the class members.

Example

The following script computes the equivalent gray intensity using all 3 of the overloads:

 

A = CColorRef:new(255,140,5)

-- create a CColorRef with values

Printf("Gray = %.2lf", A:ToGray())

-- result: Gray = 158.19

B = CColorRef:new(A)

-- create a new copy of A

B:Invert()

-- invert the colors of B

Printf("Gray = %.2lf", A:ToGray(B))

-- result: Gray = 96.81

Printf("Gray = %.2lf", B:ToGray(0,115,250))

-- result: Gray = 96.81

Related Topics

CColorRef class

Visual Response Equivalent Gray