Created
March 27, 2012 18:02
-
-
Save lamp/2218461 to your computer and use it in GitHub Desktop.
nice js code to keep
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
| var colour_map = (function(colours){ | |
| var map = {}, | |
| intervals = 100 / (colours.length - 1), | |
| count = 0, | |
| returnable = []; | |
| $.each(colours, function(i, col){ | |
| var next = parseInt(colours[i + 1], 16), | |
| current = parseInt(col, 16), | |
| count_dir = (next > current), | |
| difference = (count_dir)? next - current : current - next, | |
| increment = parseInt(difference / intervals), | |
| interval_colours = []; | |
| if(isNaN(next)) return; | |
| returnable.push(current.toString(16)); | |
| for(i = 1; i < intervals - 1; i++){ | |
| var value = (count_dir)? current + (increment * i): current - (increment * i); | |
| returnable.push(value.toString(16)); | |
| } | |
| }); | |
| returnable.push(colours[colours.length - 1]); | |
| return returnable; | |
| })(colours); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment