Created
July 17, 2016 15:07
-
-
Save peace098beat/98871ef2e0aa28c56912f67c11da0b5e to your computer and use it in GitHub Desktop.
[Create.js]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <script src="https://code.createjs.com/easeljs-0.8.2.min.js"></script> | |
| <script src="https://code.createjs.com/tweenjs-0.6.2.min.js"></script> | |
| <script src="https://code.createjs.com/preloadjs-0.6.2.min.js"></script> | |
| </head> | |
| <body onload="init();"> | |
| <canvas id="demoCanvas" width="500" height="300"></canvas> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| * { | |
| margin: 0; | |
| padding: 0; | |
| border: 0; | |
| } | |
| body { | |
| background: #d7e847; | |
| font: 30px sans-serif; | |
| } | |
| #demoCanvas{ | |
| background: #fff; | |
| border:2px solid #000; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //document.getElementById('helloWorld').innerHTML = 'Hello, World!'; | |
| function getRandomSign(){ | |
| var v = Math.random(); | |
| if(v>0.5){return 1;} | |
| else{return -1;}; | |
| } | |
| function createCircle(stage){ | |
| var _circle = new createjs.Shape(); | |
| _circle.graphics.beginFill("DeepSkyBlue").drawCircle(0, 0, 10); | |
| _circle.x = Math.random() * stage.canvas.width; | |
| _circle.y = Math.random() * stage.canvas.height; | |
| stage.addChild(_circle); | |
| return _circle; | |
| } | |
| var Nc = 10; | |
| function init() { | |
| // code here. | |
| var stage = new createjs.Stage("demoCanvas"); | |
| if (createjs.Touch.isSupported()) { | |
| createjs.Touch.enable(stage); | |
| } | |
| // オブジェクト | |
| var circles = []; | |
| for(var i=0; i<Nc; i++){ | |
| circles.push(createCircle(stage)); | |
| } | |
| // Event | |
| circles.forEach(function(circle,index,array){ | |
| circle.addEventListener("click", handleClick); | |
| function handleClick(evt) { | |
| circle.y += 50; | |
| } | |
| }); | |
| // Mouse Over | |
| stage.enableMouseOver(30); | |
| // Mouse Cursor | |
| circles.forEach(function(circle,index,array){ circle.cursor = "pointer"; }); | |
| // Animation | |
| createjs.Ticker.setFPS(20); | |
| createjs.Ticker.addEventListener("tick", stage); | |
| createjs.Ticker.useRAF = true; | |
| /********************************************/ | |
| /* Update Main Animation | |
| /********************************************/ | |
| createjs.Ticker.addEventListener("tick", handleTick); | |
| function handleTick() { | |
| circles.forEach(function(circle, index, array) { | |
| circle.x += 5; | |
| circle.y += Math.floor(Math.random()*10) * getRandomSign(); | |
| if (circle.x > stage.canvas.width) { circle.x = 0; } | |
| if (circle.x < 0) { circle.x = stage.canvas.width; } | |
| if (circle.y > stage.canvas.height) { circle.y = 0; } | |
| if (circle.y < 0) { circle.y = stage.canvas.height; } | |
| }); | |
| stage.update(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment