-
Notifications
You must be signed in to change notification settings - Fork 0
/
animation.js
35 lines (31 loc) · 900 Bytes
/
animation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* global requestAnimFrame */
function Animation(canvas) {
this.setCanvas(canvas);
this.stop = false;
window.requestAnimFrame =
window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame;
}
Animation.prototype.setCanvas = function (canvas) {
this.canvas = canvas || null;
return this.canvas;
};
Animation.prototype.getCanvas = function () {
return this.canvas;
};
Animation.prototype.loop = function () {
if (!this.stop)
this.getCanvas().draw();
requestAnimFrame(this.loop.bind(this));
};
Animation.prototype.run = function () {
var self = this;
document.addEventListener('click', function() {
self.stop = !self.stop;
});
requestAnimFrame(this.loop.bind(this));
return this;
};