Last active
December 31, 2016 04:30
-
-
Save tranch/f8563e1781aa21499dd91bb964938b15 to your computer and use it in GitHub Desktop.
github new year comment legends.
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 getWord(s) { | |
| var ascii = [], | |
| font = { | |
| // 0: | |
| // 1: * | |
| // 2: * | |
| // 3: ** | |
| // 4:* | |
| // 5:* * | |
| // 6:** | |
| // 7:*** | |
| A: [2, 5, 5, 7, 5, 5, 5], | |
| E: [7, 4, 4, 7, 4, 4, 7], | |
| H: [5, 5, 5, 7, 5, 5, 5], | |
| N: [7, 5, 5, 5, 5, 5, 5], | |
| P: [7, 5, 5, 7, 4, 4, 4], | |
| R: [7, 5, 5, 5, 6, 5, 5], | |
| W: [5, 5, 5, 5, 7, 7, 5], | |
| Y: [5, 5, 5, 5, 2, 2, 2], | |
| _: [0, 0, 0, 0, 0, 0, 0], | |
| }; | |
| s.split('').forEach(function(c) { | |
| var size = (font[c].reduce(function(r, a) { | |
| return r | a; | |
| }, 0)).toString(2).length; | |
| font[c].forEach(function(a, i) { | |
| var temp = a.toString(2).split('').map(function(c) { | |
| return +c ? '*' : ' '; | |
| }); | |
| while (temp.length < size) { | |
| temp.unshift(' '); | |
| } | |
| ascii[i] = ascii[i] || []; | |
| ascii[i].push(temp.join('')); | |
| }); | |
| }); | |
| return ascii.map(function(a) { | |
| return a.join(' '); | |
| }).join('\n'); | |
| } | |
| var rows = getWord('HAPPY_NEW_YEAR_').split('\n'), | |
| days = document.querySelectorAll('.calendar-graph .day'), | |
| colors = document.querySelectorAll('.legend li'); | |
| for (var i = 0, day; day = days[i]; i++) { | |
| var char = rows[i % rows.length][Math.floor(i / rows.length)], | |
| level = colors.length - 1; | |
| if (char == ' ') { | |
| level = Math.floor((colors.length - 2) * Math.random()); | |
| } | |
| day.style.fill = colors[level].style.backgroundColor; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment