Skip to content

Instantly share code, notes, and snippets.

@kobake
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kobake/6d8d3c71f940bbd49da2 to your computer and use it in GitHub Desktop.
Save kobake/6d8d3c71f940bbd49da2 to your computer and use it in GitHub Desktop.
console log wave
function hex2(n){
var ret = Number(n).toString(16);
if(ret.length < 2)ret = '0' + ret;
return ret;
}
function rgb(r,g,b){
return '#' + hex2(r % 256) + hex2(g % 256) + hex2(b % 256);
}
var Ball = function(index){
this.x = 0;
this.index = index;
this.time = index * 10;
this.color = rgb(80 + index * 8, 50 + index * 5, 150 - index * 7);
this.frame = function(){
this.time += 3;
this.x = 100 + 100 * Math.sin(this.time / 180 * 3.1415);
}
this.render = function(){
console.log(
'%c■%c' + this.index,
'padding: ' + this.x + 'px; color: ' + this.color + ';',
'color: #fff'
);
}
};
var balls = [];
for(var i = 0; i < 20; i++){
balls.push(new Ball(i));
}
setInterval(function(){
for(var i = 0; i < balls.length; i++){
balls[i].frame();
}
console.clear();
for(var i = 0; i < balls.length; i++){
balls[i].render();
}
}, 50);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment