Created
August 15, 2013 12:24
-
-
Save aslushnikov/6240417 to your computer and use it in GitHub Desktop.
Code snippet to generate a contrast colors for some object types.
Consider you have a text written in different fonts, and you want to highlight every character with its own color
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function generatePalette() | |
{ | |
// example of test input | |
var fontsPalette = { | |
"Times New Roman": "", | |
"Arial": "", | |
"Verdana": "" | |
}; | |
var fonts = Object.keys(fontsPalette); | |
var amount = Object.keys(fonts).length; | |
var base = 0.9; | |
var shadeFactor = (1 - base) * 8 / amount; | |
var add = [0, 0, 0]; | |
for(var i = 0; i < amount; ++i) { | |
var step = shadeFactor * (i >> 3); | |
for(var j = 0; j < 3; ++j) | |
add[j] = (i & (1 << j)) ? shadeFactor + step : step; | |
fontsPalette[fonts[i]] = new WebInspector.Color([base + add[1], base + add[0], base + add[2]], WebInspector.Color.Format.RGB); | |
} | |
return fontsPalette; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment