Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <script>
- var Template = {};
- var requestAnimationFrame =
- window.requestAnimationFrame||
- window.webkitRequestAnimationFrame||
- window.mozRequestAnimationFrame||
- window.oRequestAnimationFrame||
- window.msRequestAnimationFrame;
- var cancelAnimationFrame =
- window.cancelAnimationFrame||
- window.webkitCancelRequestAnimationFrame||
- window.webkitCancelAnimationFrame||
- window.mozCancelRequestAnimationFrame||
- window.mozCancelAnimationFrame||
- window.oCancelRequestAnimationFrame||
- window.oCancelAnimationFrame||
- window.msCancelRequestAnimationFrame||
- window.msCancelAnimationFrame;
- Template.newTime = Date.now();
- Template.time = 0;
- Template.animation = function()
- {
- if(!Template.stopped)
- {
- Template.oldTime = Template.newTime;
- Template.time=Template.newTime-Template.oldTime;
- if(!Template.paused)
- {
- Template.calculate(Template.time);
- }
- Template.draw(Template.graphics);
- Template.newTime = Date.now();
- Template.animationFrame = requestAnimationFrame(Template.animation);
- }
- }
- Template.start = function(d,c,g)
- {
- Template.draw = d;
- Template.calculate = c;
- Template.paused = false;
- Template.graphics = g;
- Template.animationFrame = requestAnimationFrame(Template.animation);
- }
- Template.stop = function()
- {
- cancelAnimationFrame(Template.animationFrame);
- }
- Template.random = function(a,b)
- {
- return Math.random()*(b-a)+a;
- }
- function Transition(start,end,period,loops,func)
- {
- this.start = start;
- this.end = end;
- this.period = period;
- if(!func)this.func = function(a){return a;};
- else this.func = func;
- this.pos = 0;
- this.reversed;
- this.loop = loops;
- this.res = 0;
- this.calc=function()
- {
- if(this.reversed) this.pos -= Template.time/this.period;
- else this.pos += Template.time/this.period;
- if(this.loop===0)
- {
- this.pos = (this.pos+1)%1;
- }
- else
- {
- this.pos = Math.min(this.loop,Math.max(this.pos,0));
- }
- this.res = this.func(this.pos)*(end-start)+start;
- }
- this.get = function()
- {
- return this.res;
- }
- this.reverse = function()
- {
- this.reversed = !this.reversed;
- }
- }
- </script>
- <!--Game code-->
- <script>
- function Draw(canvas)
- {
- }
- function Calc(time)
- {
- }
- </script>
- </head>
- <body>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement