CFLib.org – Common Function Library Project

reverseColor(startingColor)

Last updated November 19, 2003

author

Matt Liotta

Version: 1 | Requires: CF5 | Library: UtilityLib

Description:
Returns the opposite of a color.

Return Values:
Returns a string.

Example:

<cfoutput>#reverseColor("ffee22")#</cfoutput>

Parameters:

Name Description Required
startingColor RGB value minus the Yes

Full UDF Source:

/**
 * Returns the opposite of a color.
 * 
 * @param startingColor      RGB value minus the #. (Required)
 * @return Returns a string. 
 * @author Matt Liotta (mliotta@r337.com) 
 * @version 1, November 18, 2003 
 */
function reverseColor(startingColor) {
    var start = InputBaseN(startingColor, 16);
    var red = InputBaseN("FF", 16);
    var green = InputBaseN("FF00", 16);
    var blue = InputBaseN("FF0000", 16);
    var tmp = "";

    invertRed = BitAnd(BitXOR(start, red), red);
    invertGreen = BitAnd(BitXOR(start, green), green);
    invertBlue = BitAnd(BitXOR(start, blue), blue);

    tmp = invertRed + invertGreen + invertBlue;
    tmp = Ucase(FormatBaseN(tmp, 16));
    if(len(tmp) is 4) tmp = "00" & tmp;

    return tmp;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson