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).
nGray = CColorRef:ToGray()
Returns the gray equivalent of the class member colors.
nGray = CColorRef:ToGray( CColorRef )
Returns the gray equivalent of the CColorRef passed as the argument.
nGray = CColorRef:ToGray( R, G, B )
Returns the gray equivalent of the specified R, G, and B values.
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.
The following script fragment 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 |