Here we go. In that app I was generating an N-step rainbow
programatically, so I was starting with the HSL values and had no need
for the reverse conversion.
<cffunction name="hslToRgb" output="false" returntype="string">
<cfargument name="hue" type="numeric" required="true" />
<cfargument name="saturation" type="numeric" required="true" />
<cfargument name="lightness" type="numeric" required="true" />
<cfscript>
var red = "";
var green = "";
var blue = "";
var base_line = "";
var top_val = "";
var differential = "";
base_line = ( (255.0 * lightness) * (1.0 - saturation) );
top_val = (255.0 * lightness);
differential = top_val - base_line;
if ((hue GT 300) OR (hue LT 60)) {
// red is the dominant colour.
red = top_val;
if (hue GT 300) {
// towards blue
blue = ((((360.0 - hue)/60.0) * differential)+base_line);
green = base_line;
} else {
// towards green
green = (((hue/60.0) * differential)+base_line);
blue = base_line;
}
} else if ((hue GTE 60) AND (hue LTE 180)) {
// green is the dominant colour
green = top_val;
if (hue LT 120) {
// toward red
red = ((((120.0 - hue)/60.0) * differential)+base_line);
blue = base_line;
} else {
// toward blue
blue = ((((hue - 120.0)/60.0) * differential)+base_line);
red = base_line;
}
} else {
// blue is the dominant colour
blue = top_val;
if (hue LT 240) {
// toward green
green = ((((240.0 - hue)/60.0) * differential)+base_line);
red = base_line;
} else {
// toward red
red = ((((hue - 240.0)/60.0) * differential)+base_line);
green = base_line;
}
}
return toTwoDigitHex(red) & toTwoDigitHex(green) & toTwoDigitHex(blue);
</cfscript>
</cffunction>
function toTwoDigitHex(value) {
if (value GT 255) {
value = 255;
}
if (value LT 0) {
value = 0;
}
value = formatBaseN(round(value), 16);
if (len(value) LT 2) {
value = "0" & value;
}
return uCase(value);
}
On Thu, Jan 15, 2009 at 2:31 PM, Barney Boisvert <[email protected]> wrote:
> I wrote a little app that did that for turning a color palette into a
> full set of needed colors (alternating row background, different
> button states, etc), but it was at my last job and I don't have the
> code anymore. Wasn't that hard to do if you can't find anything.
> Convert the RGB into HSV, and then you can tweak the components as
> needed (H and S in this case), and then convert back to RGB. The
> conversions are simple - there are all kinds of examples online.
>
> Actually, I think I've got the hsv to rgb converter in another app.
> Let me see if I can find that. Not the whole thing, but get you
> started if you can't find anything else.
>
> cheers,
> barneyb
>
> On Thu, Jan 15, 2009 at 2:21 PM, Andy Matthews <[email protected]>
> wrote:
>> Does anyone have a CFC which will return a tint of a specified hex color?
>>
>> In other words I provide a dark blue, and get the hex color for a little
>> lighter blue, or darker blue.
>>
--
Barney Boisvert
[email protected]
http://www.barneyb.com/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:318027
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4