2014-05-17 14:22:40 +00:00
|
|
|
// main thing here
|
2014-05-17 14:26:55 +00:00
|
|
|
var canvas = document.getElementById('canvas');
|
|
|
|
var ctx = canvas.getContext('2d');
|
2014-05-17 14:22:40 +00:00
|
|
|
|
|
|
|
window.requestAnimFrame = (function(){
|
|
|
|
return window.requestAnimationFrame ||
|
|
|
|
window.webkitRequestAnimationFrame ||
|
|
|
|
window.mozRequestAnimationFrame ||
|
|
|
|
function( callback ){
|
|
|
|
window.setTimeout(callback, 1000 / 60);
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
2014-05-17 14:52:25 +00:00
|
|
|
var blocks = [];
|
|
|
|
|
2014-05-17 15:13:10 +00:00
|
|
|
for (var i = 0; i < 6; i++) {
|
2014-05-17 14:52:25 +00:00
|
|
|
blocks.push(new Block(i, 'green'));
|
|
|
|
}
|
|
|
|
|
2014-05-17 15:13:10 +00:00
|
|
|
Render();
|
2014-05-17 14:22:40 +00:00
|
|
|
|
2014-05-17 14:52:25 +00:00
|
|
|
function Render() {
|
2014-05-17 15:15:53 +00:00
|
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
2014-05-17 14:52:25 +00:00
|
|
|
blocks.forEach(function(o){
|
|
|
|
o.draw();
|
2014-05-17 15:13:10 +00:00
|
|
|
});
|
2014-05-17 15:15:53 +00:00
|
|
|
requestAnimFrame(Render);
|
2014-05-17 14:26:55 +00:00
|
|
|
}
|
|
|
|
|
2014-05-17 14:52:25 +00:00
|
|
|
function Block(lane, color, time) {
|
|
|
|
this.lane = lane;
|
|
|
|
this.angle = 15 * (Math.PI / 180) + 30 * (Math.PI / 180) * lane;
|
|
|
|
this.color = color;
|
|
|
|
|
|
|
|
this.draw = function() {
|
|
|
|
ctx.translate(canvas.width / 2, canvas.height / 2);
|
|
|
|
ctx.rotate(this.angle);
|
2014-05-17 15:15:53 +00:00
|
|
|
ctx.fillStyle = '#000';
|
|
|
|
ctx.fillRect(canvas.width/2 + Math.cos(this.angle) * time, canvas.height/2 + Math.sin(this.angle) * time, 30, 30);
|
2014-05-17 14:52:25 +00:00
|
|
|
ctx.restore();
|
2014-05-17 15:15:53 +00:00
|
|
|
ctx.fillRect(200, 200, 200, 200);
|
2014-05-17 14:52:25 +00:00
|
|
|
};
|
2014-05-17 14:26:55 +00:00
|
|
|
|
2014-05-17 14:52:25 +00:00
|
|
|
if (!time) {
|
|
|
|
this.time = time;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
time = 200;
|
|
|
|
}
|
2014-05-17 14:22:40 +00:00
|
|
|
}
|