Created
May 2, 2013 05:50
-
-
Save foo9/5500385 to your computer and use it in GitHub Desktop.
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
| var canvas, doAnim, endPoint, getPoint, line, stage, startPoint, t; | |
| function getPoint(p1, p2, t) { | |
| var x, x1, x2, y, y1, y2; | |
| x1 = p1.x; | |
| y1 = p1.y; | |
| x2 = p2.x; | |
| y2 = p2.y; | |
| x = (x2 - x1) * t + x1; | |
| y = (y2 - y1) * t + y1; | |
| return new createjs.Point(x, y); | |
| } | |
| function doAnim(line, p1, p2) { | |
| var g, color; | |
| color = '#' + Math.floor(Math.random() * 16777215).toString(16); | |
| g = line.graphics.clear(); | |
| g.setStrokeStyle(2); | |
| g.beginStroke(color); | |
| g.moveTo(p1.x, p1.y); | |
| g.lineTo(p2.x, p2.y); | |
| return g.endStroke(); | |
| } | |
| canvas = document.getElementById("testCanvas"); | |
| stage = new createjs.Stage(canvas); | |
| startPoint = new createjs.Point(10, 10); | |
| endPoint = new createjs.Point(200, 290); | |
| line = new createjs.Shape(); | |
| doAnim(line, startPoint, endPoint); | |
| stage.addChild(line); | |
| t = 0; | |
| createjs.Ticker.setFPS(60); | |
| createjs.Ticker.addEventListener("tick", function (event) { | |
| if (t <= 100) { | |
| doAnim(line, startPoint, getPoint(startPoint, endPoint, t * 0.01)); | |
| t = t + 1; | |
| } | |
| stage.update(); | |
| }); | |
| stage.update(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment