Advertisement
raphaelluiz128

homehtmlionic

May 22nd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. <!DOCTYPE html>
  2.  
  3. <html>
  4. <head>
  5. <meta charset="UTF-8">
  6. <meta name="authoring-tool" content="Adobe_Animate_CC">
  7. <title>mathfuga_Canvas</title>
  8. <!-- write your code here -->
  9. <script src="createjs-2015.11.26.min.js"></script>
  10. <script src="mathfuga_Canvas.js"></script>
  11. <script>
  12. var canvas, stage, exportRoot, anim_container, dom_overlay_container, fnStartAnimation;
  13. function init() {
  14. canvas = document.getElementById("canvas");
  15. anim_container = document.getElementById("animation_container");
  16. dom_overlay_container = document.getElementById("dom_overlay_container");
  17. images = images||{};
  18. ss = ss||{};
  19. var loader = new createjs.LoadQueue(false);
  20. loader.addEventListener("fileload", handleFileLoad);
  21. loader.addEventListener("complete", handleComplete);
  22. loader.loadManifest(lib.properties.manifest);
  23. }
  24. function handleFileLoad(evt) {
  25. if (evt.item.type == "image") { images[evt.item.id] = evt.result; }
  26. }
  27. function handleComplete(evt) {
  28. //This function is always called, irrespective of the content. You can use the variable "stage" after it is created in token create_stage.
  29. var queue = evt.target;
  30. var ssMetadata = lib.ssMetadata;
  31. for(i=0; i<ssMetadata.length; i++) {
  32. ss[ssMetadata[i].name] = new createjs.SpriteSheet( {"images": [queue.getResult(ssMetadata[i].name)], "frames": ssMetadata[i].frames} )
  33. }
  34. exportRoot = new lib.mathfuga_Canvas();
  35. stage = new createjs.Stage(canvas);
  36. stage.addChild(exportRoot);
  37. stage.enableMouseOver();
  38. //Registers the "tick" event listener.
  39. fnStartAnimation = function() {
  40. createjs.Ticker.setFPS(lib.properties.fps);
  41. createjs.Ticker.addEventListener("tick", stage);
  42. }
  43. //Code to support hidpi screens and responsive scaling.
  44. function makeResponsive(isResp, respDim, isScale, scaleType) {
  45. var lastW, lastH, lastS=1;
  46. window.addEventListener('resize', resizeCanvas);
  47. resizeCanvas();
  48. function resizeCanvas() {
  49. var w = lib.properties.width, h = lib.properties.height;
  50. var iw = window.innerWidth, ih=window.innerHeight;
  51. var pRatio = window.devicePixelRatio || 1, xRatio=iw/w, yRatio=ih/h, sRatio=1;
  52. if(isResp) {
  53. if((respDim=='width'&&lastW==iw) || (respDim=='height'&&lastH==ih)) {
  54. sRatio = lastS;
  55. }
  56. else if(!isScale) {
  57. if(iw<w || ih<h)
  58. sRatio = Math.min(xRatio, yRatio);
  59. }
  60. else if(scaleType==1) {
  61. sRatio = Math.min(xRatio, yRatio);
  62. }
  63. else if(scaleType==2) {
  64. sRatio = Math.max(xRatio, yRatio);
  65. }
  66. }
  67. canvas.width = w*pRatio*sRatio;
  68. canvas.height = h*pRatio*sRatio;
  69. canvas.style.width = dom_overlay_container.style.width = anim_container.style.width = w*sRatio+'px';
  70. canvas.style.height = anim_container.style.height = dom_overlay_container.style.height = h*sRatio+'px';
  71. stage.scaleX = pRatio*sRatio;
  72. stage.scaleY = pRatio*sRatio;
  73. lastW = iw; lastH = ih; lastS = sRatio;
  74. }
  75. }
  76. makeResponsive(true,'both',true,1);
  77. fnStartAnimation();
  78. }
  79. </script>
  80. <!-- write your code here -->
  81. </head>
  82. <body onload="init();" style="margin:0px;">
  83. <div id="animation_container" style="background-color:rgba(0, 204, 255, 1.00); width:800px; height:620px">
  84. <canvas id="canvas" width="800" height="620" style="position: absolute; display: block; background-color:rgba(0, 204, 255, 1.00);"></canvas>
  85. <div id="dom_overlay_container" style="pointer-events:none; overflow:hidden; width:800px; height:620px; position: absolute; left: 0px; top: 0px; display: block;">
  86. </div>
  87. </div>
  88. </body>
  89. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement