Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Way overboard on a cool script posted by Rlemon
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;
}
cCycle = cycle + 50;
if(cCycle>100){
cCycle -= 100;
}
colorCycle(mColor, cCycle);
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();
@rlemon
Copy link

rlemon commented Jan 4, 2013

Why are you still using with(){}... I used it mostly as a jest hehehe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment