Skip to content

Instantly share code, notes, and snippets.

@jonobr1
Created November 3, 2010 05:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonobr1/660832 to your computer and use it in GitHub Desktop.
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
<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