Toolkit.Drawing = {} Toolkit.Math = { degToRad: function(x) { return (x*Math.PI) / 180; }, radToDeg: function(x) { return (angle*180) / Math.PI; }, factorial: function(n) { if(n<1) { return 0; } var retVal = 1; for(var i=1;i<=n;i++) retVal *= i; return retVal; }, //The number of ways of obtaining an ordered subset of k elements from a set of n elements permutations: function(n,k) { if(n==0 || k==0) return 1; return (Toolkit.Math.factorial(n) / Toolkit.Math.factorial(n-k)); }, //The number of ways of picking n unordered outcomes from r possibilities combinations: function(n,r) { if(n==0 || r==0) return 1; return (Toolkit.Math.factorial(n) / (Toolkit.Math.factorial(n-r) * Toolkit.Math.factorial(r))); }, bernstein: function (t,n,i) { return ( Toolkit.Math.combinations(n,i) * Math.pow(t,i) * Math.pow(1-t,n-i) ); } }; //A collection of objects that define curves, use getValue(n) //to get a point on the curve where 0 <= n <= 1 //Unless otherwise stated all curves are n-dimensional, using arrays to represent coordinates. All arrays must be of //same length otherwise errors will occur! Toolkit.Drawing.Curves = { //Creates a straight line object Line: function(start, end) { this.start = start; this.end = end; this.dimensions = start.length; //simple function to find point on an n-dimensional, straight line this.getValue = function(n) { var retVal = new Array(this.dimensions); for(var i=0;i= this.p.length) i1 = this.p.length-1; var i2 = node+2; if(i2 >= this.p.length) i2 = this.p.length-1; var u = progress; var u2 = progress*progress; var u3 = progress*progress*progress; var retVal = new Array(this.p[0].length); for(var k=0;k1) step=1; this.percent = step*100; this.fps = 1000 / ((new Date().valueOf()) - this.lastFrame); this.lastFrame = new Date().valueOf(); this.active = false; var substep = step; if(this.acc != 0) substep = this.speedCurve.getValue(step)[0]; var e = null; if(gotoEnd) e = { coordinates: this.curve.getValue(1), startTime: this.startTime, duration: this.duration, percent: this.percent, fps: Math.round(this.fps) }; else e = { coordinates: this.curve.getValue(substep), startTime: this.startTime, duration: this.duration, percent: this.percent, fps: Math.round(this.fps) }; this.onanimate(e); this.onend(e); } this.cycle = function() { var curTime = new Date().valueOf(); var step = (curTime - this.startTime) / (this.endTime - this.startTime); this.percent = step*100; this.fps = 1000 / ((new Date().valueOf()) - this.lastFrame); this.lastFrame = new Date().valueOf(); if(step <= 1 && this.active == true) { var substep = step; if(this.acc != 0) substep = this.speedCurve.getValue(step)[0]; this.onanimate({ coordinates: this.curve.getValue(substep), startTime: this.startTime, duration: this.duration, percent: this.percent, fps: Math.round(this.fps) }); setTimeout("Toolkit.Drawing.animations[" + this.id + "].cycle()",5); } else if(this.active==true) { this.active = false; var e = { coordinates: this.curve.getValue(1), startTime: this.startTime, duration: this.duration, percent: this.percent, fps: Math.round(this.fps) }; this.onanimate(e); this.onend(e); } } //return this; }