Created
November 3, 2010 05:50
-
-
Save jonobr1/660832 to your computer and use it in GitHub Desktop.
pseudo code for question on tween.js library. https://github.com/sole/tween.js/issues/issue/7
This file contains 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> | |
<script type = "text/javascript" src = "tween.js"></script> | |
<script> | |
var g, canvas; | |
var objects = []; | |
function init() { | |
canvas = document.createElement('canvas'); | |
document.body.appendChild(canvas); | |
g = canvas.getContext('2d'); | |
objects.length = 5; | |
for(var i = 0; i < objects.length; i++) { | |
objects[i] = new Drip(); | |
objects[i].setup(); | |
} | |
setInterval(loop, 1000/20); | |
} | |
function loop() { | |
TWEEN.update(); | |
for(var i = 0; i < objects.length; i++) { | |
objects[i].render(); | |
} | |
} | |
function Drip() { | |
this.p; | |
this.tween; | |
this.setup = function() { | |
this.p = {x: 0, y: 0} | |
this.tween = new TWEEN.Tween(this.p).to({x: 500, y: 500}, 1000).start(); | |
this.tween.easing(TWEEN.Easing.Quadratic.EaseIn); | |
} | |
this.render = function() { | |
g.strokeStyle = "#000" | |
g.lineWidth = 10; | |
g.beginPath(); | |
g.moveTo(0,0); | |
g.lineTo(this.p.x, this.p.y); | |
g.stroke(); | |
} | |
} | |
</script> | |
<body onload="init()"> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment