Advertisement
nzisaacnz

Template

Feb 25th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 2.23 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script>
  5. var Template = {};
  6. var requestAnimationFrame =
  7. window.requestAnimationFrame||
  8. window.webkitRequestAnimationFrame||
  9. window.mozRequestAnimationFrame||
  10. window.oRequestAnimationFrame||
  11. window.msRequestAnimationFrame;
  12.  
  13. var cancelAnimationFrame =
  14. window.cancelAnimationFrame||
  15. window.webkitCancelRequestAnimationFrame||
  16. window.webkitCancelAnimationFrame||
  17. window.mozCancelRequestAnimationFrame||
  18. window.mozCancelAnimationFrame||
  19. window.oCancelRequestAnimationFrame||
  20. window.oCancelAnimationFrame||
  21. window.msCancelRequestAnimationFrame||
  22. window.msCancelAnimationFrame;
  23.  
  24. Template.newTime = Date.now();
  25. Template.time = 0;
  26. Template.animation = function()
  27. {
  28.  if(!Template.stopped)
  29.  {
  30.   Template.oldTime = Template.newTime;
  31.   Template.time=Template.newTime-Template.oldTime;
  32.   if(!Template.paused)
  33.   {
  34.    Template.calculate(Template.time);
  35.   }
  36.   Template.draw(Template.graphics);
  37.   Template.newTime = Date.now();
  38.   Template.animationFrame = requestAnimationFrame(Template.animation);
  39.  }
  40. }
  41. Template.start = function(d,c,g)
  42. {
  43.  Template.draw = d;
  44.  Template.calculate = c;
  45.  Template.paused = false;
  46.  Template.graphics = g;
  47.  Template.animationFrame = requestAnimationFrame(Template.animation);
  48. }
  49. Template.stop = function()
  50. {
  51.  cancelAnimationFrame(Template.animationFrame);
  52. }
  53. Template.random = function(a,b)
  54. {
  55.  return Math.random()*(b-a)+a;
  56. }
  57. function Transition(start,end,period,loops,func)
  58. {
  59.  this.start = start;
  60.  this.end = end;
  61.  this.period = period;
  62.  if(!func)this.func = function(a){return a;};
  63.  else this.func = func;
  64.  this.pos = 0;
  65.  this.reversed;
  66.  this.loop = loops;
  67.  this.res = 0;
  68.  this.calc=function()
  69.  {
  70.   if(this.reversed) this.pos -= Template.time/this.period;
  71.   else this.pos += Template.time/this.period;
  72.   if(this.loop===0)
  73.   {
  74.    this.pos = (this.pos+1)%1;
  75.   }
  76.   else
  77.   {
  78.    this.pos = Math.min(this.loop,Math.max(this.pos,0));
  79.   }
  80.   this.res = this.func(this.pos)*(end-start)+start;
  81.  }
  82.  this.get = function()
  83.  {
  84.   return this.res;
  85.  }
  86.  this.reverse = function()
  87.  {
  88.   this.reversed = !this.reversed;
  89.  }
  90. }
  91. </script>
  92. <!--Game code-->
  93. <script>
  94. function Draw(canvas)
  95. {
  96.  
  97. }
  98. function Calc(time)
  99. {
  100.  
  101. }
  102. </script>
  103. </head>
  104. <body>
  105.  
  106. </body>
  107. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement