Created
June 24, 2015 16:01
-
-
Save shash7/a90166f032c5278eaad9 to your computer and use it in GitHub Desktop.
Turn text into panels to create a visual hierachy
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
var stretch = 1; | |
function parseRGB(input) { | |
m = input.match(/^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i); | |
if( m) { | |
return [parseInt(m[1]),parseInt(m[2]),parseInt(m[3])]; | |
} else { | |
return null; | |
} | |
} | |
function normalize(num) { | |
if(num > 255) { | |
num = 255; | |
} | |
if(num < 0) { | |
num = 0; | |
} | |
return num; | |
} | |
function setRGB(arr) { | |
return 'rgb(' + arr[0] + ',' + arr[1] + ',' + arr[2] + ')'; | |
} | |
undefined | |
function randomize(arr) { | |
arr = arr.map(function(data) { | |
var upper = data + stretch; | |
var temp = (Math.random()*upper) + stretch; | |
return normalize(Math.round(temp)); | |
}); | |
return arr; | |
} | |
function invert(rgb) { | |
rgb = [].slice.call(arguments).join(",").replace(/rgb\(|\)|rgba\(|\)|\s/gi, '').split(','); | |
for (var i = 0; i < rgb.length; i++) rgb[i] = (i === 3 ? 1 : 255) - rgb[i]; | |
return rgb; | |
} | |
$('*').each(function() { | |
var el = $(this); | |
if(el.is('p') || el.is('span') || el.is('a') || el.is('h1') || el.is('h2') || el.is('input') || el.is('ul') || el.is('b')) { | |
var color = el.css('color'); | |
color = invert(color); | |
//color = parseRGB(color); | |
console.log(color); | |
color = randomize(color); | |
color = setRGB(color); | |
el.css({'background-color' : color, 'color' : color, 'border-color' : color, 'border-radius' : '3px' }); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment