Sign in
Log inSign up

Little pieces of code, to brighten up your day

Björn's photo
Björn
·Aug 6, 2015

Sometimes i wonder if other people are as crazy as i am.

If I am bored at work, I start writing useless code, to play around on some websites, for example:

var one = [1, false];
var two = [2, false];
var three = [3, false];
setInterval(function() {
    if(one[0] > 254 && !one[1]) {
        one[1] = !one[1];
    } else if (one[0] < 1 && one[1]){
        one[1] = !one[1];
    } else {
        if(one[1]) {
            one[0] = one[0] - 1;
        } else {
            one[0] = one[0] + 1;
        }
    }
    if(two[0] > 253 && !two[1]) {
        two[1] = !two[1];
    } else if (two[0] < 2 && two[1]){
        two[1] = !two[1];
    } else {
        if(two[1]) {
            two[0] = two[0] - 2;
        } else {
            two[0] = two[0] + 2;
        }
    }
    if(three[0] > 252 && !three[1]) {
        three[1] = !three[1];
    } else if (three[0] < 3 && three[1]){
        three[1] = !three[1];
    } else {
        if(three[1]) {
            three[0] = three[0] - 3;
        } else {
            three[0] = three[0] + 3;
        }
    }

    $('body').css({
        "background": "rgba(" + one[0] + ", " + two[0] + ", " + three[0] + ",1)"
    });
}, 10);

Which simply changes the color of a given element every 10 seconds. Or:

var degree = 0;
interval = setInterval(function(){
	if(degree == 359) {
		degree = 0;
	} else {
		degree+=1;
	}
	$('#loadingBorder').css({ WebkitTransform: 'rotate(' + degree + 'deg)'});
	$('#loadingBorder').css({ '-moz-transform': 'rotate(' + degree + 'deg)'});
}, 30);

To spin buttons around.

Do you have code like this too, to brighten up your day? Or maybe draw mustaches on faces etc?