Last active
August 29, 2015 14:23
-
-
Save janbaykara/d36b36652c4a8563dee4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 strToHSL(input) { | |
return intToHSL(getHashCode(input)); | |
function intToHSL(int) { | |
var shortened = int % 360; | |
return "hsla(" + shortened + ",70%,40%,0.4)"; | |
}; | |
function getHashCode(str) { | |
var hash = 0; | |
if (str.length == 0) return hash; | |
// // Colour by random sum int | |
// for (var i = 0; i < str.length; i++) { | |
// hash = str.charCodeAt(i) + ((hash << 5) - hash); | |
// hash = hash & hash; // Convert to 32bit integer | |
// } | |
// return hash; | |
// // Colour by aggregate difference in chars | |
// for (var i = 0; i < str.length; i++) { | |
// hash += str.charCodeAt(i) - 97 | |
// } | |
// return hash; | |
// // Colour by text difference average | |
var i = 0; | |
while (i < str.length) { | |
hash += (str.charCodeAt(i) - 97) * 30 | |
i++; | |
} | |
return hash/i; | |
}; | |
} | |
$("#task_list .package").each(function() { | |
var color = strToHSL( $(this).text() ); | |
$(this).attr('style','background: '+color+' !important; color: white !important;') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment