Last active
August 29, 2015 14:05
-
-
Save joshhunt/ae99630fdeaf22d74a76 to your computer and use it in GitHub Desktop.
rainbow log
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
| define [], -> | |
| # Wrap console.log to make it safe to use in IE | |
| log = -> console?.log? arguments... | |
| log.rainbow = (text, fontSize) -> | |
| rainbow = [ | |
| 'rgb(0, 230, 0)' | |
| 'rgb(0, 230, 230)' | |
| 'rgb(0, 0, 230)' | |
| 'rgb(230, 0, 230)' | |
| 'rgb(230, 0, 0)' | |
| 'rgb(230, 230, 0)' | |
| 'rgb(0, 230, 0)' | |
| ] | |
| shadows = [ | |
| # Start out with fake 3D effect | |
| 'rgb(238, 238, 238) 0px 1px 0px' | |
| 'rgb(201, 201, 201) 0px 2px 0px' | |
| 'rgb(187, 187, 187) 0px 3px 0px' | |
| 'rgb(185, 185, 185) 0px 4px 0px' | |
| 'rgb(170, 170, 170) 0px 5px 0px' | |
| 'rgba(0, 0, 0, 0.0980392) 0px 6px 1px' | |
| 'rgba(0, 0, 0, 0.0980392) 0px 0px 5px' | |
| 'rgba(0, 0, 0, 0.298039) 0px 1px 3px' | |
| 'rgba(0, 0, 0, 0.2) 0px 3px 5px' | |
| 'rgba(0, 0, 0, 0.247059) 0px 5px 10px' | |
| 'rgba(0, 0, 0, 0.2) 0px 10px 10px' | |
| 'rgba(0, 0, 0, 0.14902) 0px 20px 20px' | |
| ] | |
| # Default font size to 40 and make the rainbow roughly double the height of the text | |
| fontSize ?= 40 | |
| colorDepth = Math.ceil fontSize / rainbow.length | |
| shadowDepth = 1 | |
| # Fake a rainbow by drawing out multiple text-shadows with no spread down like 'steps' | |
| for color in rainbow | |
| for d in [0...colorDepth] | |
| shadows.push "#{color} #{shadowDepth}px #{shadowDepth + 5}px" | |
| shadowDepth += 1 | |
| # Join everything together to make the valid text-shadow value | |
| shadowStr = shadows.join ',' | |
| style = [ | |
| 'font-family: \'Helvetica Neue\'' | |
| "font-size: #{fontSize}px" | |
| 'color: white' | |
| 'font-weight: bold' | |
| "text-shadow: #{shadowStr}" | |
| 'line-height: 3' | |
| ] | |
| # Finally print it all. %c format string prints out the css | |
| log '%c' + text, style.join '; ' | |
| return log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment