Created
January 3, 2013 17:16
-
-
Save anonymous/4445057 to your computer and use it in GitHub Desktop.
Way overboard on a cool script posted by Rlemon
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
function r() { | |
return Math.floor(Math.random() * 255); | |
} | |
function lemon() { | |
var cycle = parseFloat(this.dataset.cycle); | |
if(isNaN(cycle)){ | |
cycle = ~~(Math.random()*100); | |
} | |
with(this.style) { | |
var matchColor = /rgb\((\d{1,3}), (\d{1,3}), (\d{1,3})\)/, | |
match = matchColor.exec(color), | |
mColor = {r:r(), g:r(), b:r()}, | |
bColor = {r:r(), g:r(), b:r()}; | |
if(match !== null) { | |
mColor = {r:match[1], g:match[2], b:match[3]} | |
} | |
match = matchColor.exec(backgroundColor); | |
if(match !== null) { | |
bColor = {r:match[1], g:match[2], b:match[3]}; | |
} | |
cycle+=0.5; | |
if(cycle>100){ | |
cycle = 0; | |
} | |
colorCycle(mColor, cycle); | |
colorCycle(bColor, cycle); | |
color = "rgb(" +mColor.r+","+mColor.g+","+mColor.b+")"; | |
backgroundColor = "rgb(" +bColor.r+","+bColor.g+","+bColor.b+")"; | |
} | |
this.dataset.cycle = cycle; | |
} | |
function rocks() { | |
Array.prototype.forEach.call(document.all, function(item) { | |
setTimeout(function() { | |
lemon.call(item); | |
}, 10); | |
}); | |
setTimeout(rocks, 10); | |
} | |
function colorCycle(color, cycle){ | |
color.r = ~~(Math.sin(.3*cycle + 0) * 127+ 128); | |
color.g = ~~(Math.sin(.3*cycle + 2) * 127+ 128); | |
color.b = ~~( Math.sin(.3*cycle + 4) * 127+ 128); | |
} | |
rocks(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment