Skip to content

Instantly share code, notes, and snippets.

@tonyjunkes
Created March 19, 2021 20:35
Show Gist options
  • Save tonyjunkes/13d6f5ac95b8fa91f2ecd007f48e966e to your computer and use it in GitHub Desktop.
Save tonyjunkes/13d6f5ac95b8fa91f2ecd007f48e966e to your computer and use it in GitHub Desktop.
Returns an array of hex based colors starting from a provided color and shifting from dark to light or the reverse.
<cfscript>
array function shadeColors(string color, numeric percent, numeric iteration) {
var result = [];
var currentcolor = arguments.color;
for (var i = 0; i < arguments.iteration; i++) {
var R = inputBaseN(currentcolor.mid(1, 2), 16);
var G = inputBaseN(currentcolor.mid(3, 2), 16);
var B = inputBaseN(currentcolor.mid(5, 2), 16);
R = formatBaseN(R * (100 + percent) / 100, 10);
G = formatBaseN(G * (100 + percent) / 100, 10);
B = formatBaseN(B * (100 + percent) / 100, 10);
R = (R < 255) ? R : 255;
G = (G < 255) ? G : 255;
B = (B < 255) ? B : 255;
var RF = formatBaseN(R, 16);
var RR = ((len(RF) == 1) ? '0' + RF : RF);
var GF = formatBaseN(G, 16);
var GG = ((len(GF) == 1) ? '0' + GF : GF);
var BF = formatBaseN(B, 16);
var BB = ((len(BF) == 1) ? '0' + BF : BF);
currentcolor = RR & GG & BB;
result.append("##" & currentcolor);
}
return result;
}
writedump(shadeColors("14578d", 5, 20));
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment