Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

physics2d package is completed. All constraints, behaviors, springs h…

…ave been tested and work correctly
  • Loading branch information...
commit 24bd181936ed4113cae70430d5751d623b13390a 1 parent cf973a1
@hapticdata hapticdata authored
View
34 README.md
@@ -1,11 +1,21 @@
-Toxiclibs.js is a javascript port of Karsten Schmidt's Toxiclibs for Java and Processing. Toxiclibs.js works great with the Processing.js visualization library for <canvas> but is not dependent on it. It can be used with other libraries such as Raphael.js, Three.js or by itself.
+[Toxiclibs.js](http://haptic-data.com/toxiclibsjs) is a javascript port of [Karsten Schmidt's Toxiclibs](http://toxiclibs.org) for Java and Processing. Toxiclibs.js works great with the Processing.js visualization library for <canvas> but is not dependent on it. It can be used with any other library or by itself.
-* Examples of toxiclibs.js can be found at [http://haptic-data.com/toxiclibsjs](http://haptic-data.com/toxiclibsjs)
+* Examples of toxiclibs.js can be found at [http://haptic-data.com/toxiclibsjs](http://haptic-data.com/toxiclibsjs), and are included in the examples/ folder of the repository.
* Examples of the original library can be found at [http://toxiclibs.org](http://toxiclibs.org)
+### A few examples ###
+[![additive_waves](http://haptic-data.com/toxiclibsjs/img/additive_waves.jpg)](http://haptic-data.com/toxiclibsjs/examples/AdditiveWaves_pjs-webgl.html)
+[![smooth_doodle](http://haptic-data.com/toxiclibsjs/img/smooth_doodle.gif)](http://haptic-data.com/toxiclibsjs/examples/SmoothDoodle_canvas.html)
+[![polar_unravel](http://haptic-data.com/toxiclibsjs/img/img/polar_unravel.gif)](http://haptic-data.com/toxiclibsjs/examples/PolarUnravel_pjs.html)
+[![circle_3_points](http://haptic-data.com/toxiclibsjs/img/circle_3_points.gif)](http://haptic-data.com/toxiclibsjs/examples/Circle3Points_pjs.html)
+[![line2d_intersection](http://haptic-data.com/toxiclibsjs/img/line2d_intersection.gif)](http://haptic-data.com/toxiclibsjs/examples/Line2DIntersection_pjs.html)
+
+
+
+
classes currently in the toxiclibs.js compiled build:
Geometry (toxi. namespace)
@@ -66,6 +76,26 @@ Color (toxi.color. namespace)
* TColor
+VerletPhysics2D (toxi.physics2d namespace)
+
+* VerletParticle2D
+* VerletSpring2D
+* AttractionBehavior
+* ConstantForceBehavior
+* GravityBehavior
+* AngularConstraint
+* AxisConstraint
+* CircularConstraint
+* MaxConstraint
+* MinConstraint
+* RectConstraint
+* ParticlePath2D
+* ParticleString2D
+* PullBackString2D
+* VerletConstrainedSpring2D
+* VerletMinDistanceSpring2D
+* VerletPhysics2D
+
[http://haptic-data.com/toxiclibsjs](Toxiclibs.js) was initiated on 1/5/2011 by Kyle Phillips [http://haptic-data.com](http://haptic-data.com)
View
2  build/toxi-color.js
@@ -1,4 +1,4 @@
-// toxi-color.js r33 - http://github.com/hapticdata/toxiclibsjs
+// toxi-color.js r34 - http://github.com/hapticdata/toxiclibsjs
toxi.color=toxi.color===undefined?{}:toxi.color;toxi.color.TColor=function(a){this.rgb=Array(3);this.hsv=Array(3);this.cmyk=Array(4);this._alpha=1;if(a!==undefined){this.cmyk=a.toCMYKAArray().splice(0,4);this.hsv=a.toHSVAArray().splice(0,3);this.rgb=a.toRGBAArray().splice(0,3);this._alpha=a._alpha}};
toxi.color.TColor.prototype={add:function(a){return this.copy().addSelf(a)},addSelf:function(a){this.rgb[0]=toxi.MathUtils.min(this.rgb[0]+a.rgb[0],1);this.rgb[1]=toxi.MathUtils.min(this.rgb[1]+a.rgb[1],1);this.rgb[2]=toxi.MathUtils.min(this.rgb[2]+a.rgb[2],1);return this.setRGB(rgb)},adjustConstrast:function(a){return this.hsv[2]<0.5?this.darken(a):this.lighten(a)},adjustHSV:function(a,b,d){return this.setHSV([this.hsv[0]+a,this.hsv[1]+b,this.hsv[2]+d])},adjustRGB:function(a,b,d){return this.setRGB([this.rgb[0]+
a,this.rgb[1]+b,this.rgb[2]+d])},alpha:function(){return this._alpha},analog:function(a,b){this.rotateRYB(toxi.MathUtils.degrees(a)*toxi.MathUtils.normalizedRandom());this.hsv[1]+=b*toxi.MathUtils.normalizedRandom();this.hsv[2]+=b*toxi.MathUtils.normalizedRandom();return this.setHSV(this.hsv)},black:function(){return this.cmyk[3]},blend:function(a,b){if(b===undefined)b=0.5;var d=a.toRGBAArray();this.rgb[0]+=(d[0]-this.rgb[0])*b;this.rgb[1]+=(d[1]-this.rgb[1])*b;this.rgb[2]+=(d[2]-this.rgb[2])*b;this._alpha+=
View
29 build/toxi-core.js
@@ -1,4 +1,4 @@
-// toxi-core.js r33 - http://github.com/hapticdata/toxiclibsjs
+// toxi-core.js r34 - http://github.com/hapticdata/toxiclibsjs
var toxi=toxi||{};toxi.extend=function(e,g){e.prototype=new g;e.constructor=e;e.prototype.parent=g.prototype};toxi.MathUtils={};toxi.MathUtils.SQRT2=Math.sqrt(2);toxi.MathUtils.SQRT3=Math.sqrt(3);toxi.MathUtils.LOG2=Math.log(2);toxi.MathUtils.PI=3.141592653589793;toxi.MathUtils.INV_PI=1/toxi.MathUtils.PI;toxi.MathUtils.HALF_PI=toxi.MathUtils.PI/2;toxi.MathUtils.THIRD_PI=toxi.MathUtils.PI/3;toxi.MathUtils.QUARTER_PI=toxi.MathUtils.PI/4;toxi.MathUtils.TWO_PI=toxi.MathUtils.PI*2;
toxi.MathUtils.THREE_HALVES_PI=toxi.MathUtils.TWO_PI-toxi.MathUtils.HALF_PI;toxi.MathUtils.PI_SQUARED=toxi.MathUtils.PI*toxi.MathUtils.PI;toxi.MathUtils.EPS=1.1920928955078125E-7;toxi.MathUtils.DEG2RAD=toxi.MathUtils.PI/180;toxi.MathUtils.RAD2DEG=180/toxi.MathUtils.PI;toxi.MathUtils.SHIFT23=8388608;toxi.MathUtils.INV_SHIFT23=1/toxi.MathUtils.SHIFT23;toxi.MathUtils.SIN_A=-4/(toxi.MathUtils.PI*toxi.MathUtils.PI);toxi.MathUtils.SIN_B=4/toxi.MathUtils.PI;toxi.MathUtils.SIN_P=0.225;
toxi.MathUtils.abs=Math.abs;toxi.MathUtils.ceilPowerOf2=function(e){for(var g=1;g<e;)g<<=1;return g};toxi.MathUtils.clip=function(e,g,h){return e<g?g:e>h?h:e};toxi.MathUtils.clipNormalized=function(e){if(e<0)return 0;else if(e>1)return 1;return e};toxi.MathUtils.cos=Math.cos;toxi.MathUtils.fastCos=function(e){return toxi.MathUtils.fastSin(e+(e>toxi.MathUtils.HALF_PI?-toxi.MathUtils.THREE_HALVES_PI:toxi.MathUtils.HALF_PI))};
@@ -33,11 +33,11 @@ toxi.FMTriangleWave.prototype.pop=function(){this.parent.pop.call(this);this.fmo
toxi.SineWave=function(e,g,h,i){this.parent.init.call(this,e,g,h,i)};toxi.SineWave.prototype=new toxi.AbstractWave;toxi.SineWave.constructor=toxi.SineWave;toxi.SineWave.prototype.parent=toxi.AbstractWave.prototype;toxi.SineWave.prototype.getClass=function(){return"SineWave"};toxi.SineWave.prototype.pop=function(){this.parent.pop.call(this)};toxi.SineWave.prototype.push=function(){this.parent.push.call(this)};
toxi.SineWave.prototype.update=function(){this.value=Math.sin(this.phase)*this.amp+this.offset;this.cyclePhase(this.frequency);return this.value};toxi.WaveState=function(e,g,h,i){this.phase=e;this.frequency=g;this.amp=h;this.offset=i};toxi.SinCosLUT=function(e){this.precision=e;this.period=360/this.precision;this.quadrant=this.period>>2;this.deg2rad=Math.PI/180*this.precision;this.rad2deg=180/Math.PI/this.precision;this.sinLUT=[];for(e=0;e<this.period;e++)this.sinLUT[e]=Math.sin(e*this.deg2rad)};
toxi.SinCosLUT.prototype={cos:function(e){for(;e<0;)e+=toxi.MathUtils.TWO_PI;return this.sinLUT[(e*this.rad2deg+this.quadrant)%this.period]},getPeriod:function(){return this.period},getPrecision:function(){return this.precision},getSinLUT:function(){return this.sinLUT},sin:function(e){for(;e<0;)e+=toxi.MathUtils.TWO_PI;return this.sinLUT[e*this.rad2deg%this.period]}};toxi.SinCosLUT.DEFAULT_PRECISION=0.25;toxi.SinCosLUT.DEFAULT_INSTANCE=null;
-toxi.SinCosLUT.getDefaultInstance=function(){if(toxi.SinCosLUT.DEFAULT_INSTANCE==null)toxi.SinCosLUT.DEFAULT_INSTANCE=new toxi.SinCosLUT;return toxi.SinCosLUT.DEFAULT_INSTANCE};toxi.Vec2D=function(e,g){this.init(e,g)};
+toxi.SinCosLUT.getDefaultInstance=function(){if(toxi.SinCosLUT.DEFAULT_INSTANCE==null)toxi.SinCosLUT.DEFAULT_INSTANCE=new toxi.SinCosLUT;return toxi.SinCosLUT.DEFAULT_INSTANCE};toxi.Vec2D=function(e,g){this.init(e,g)};toxi.Vec2D.Axis={X:{getVector:function(){return toxi.Vec2D.X_AXIS},toString:function(){return"toxi.Vec2D.Axis.X"}},Y:{getVector:function(){return toxi.Vec2D.Y_AXIS},toString:function(){return"toxi.Vec2D.Axis.Y"}}};
toxi.Vec2D.prototype={abs:function(){this.x=Math.abs(this.x);this.y=Math.abs(this.y);return this},add:function(e,g){var h=this.getVector(e,g);return new toxi.Vec2D(this.x+h.x,this.y+h.y)},addSelf:function(e,g){var h=this.getVector(e,g);this.x+=h.x;this.y+=h.y;return this},angleBetween:function(e,g){var h;h=g!==undefined&&faceNormalize==true?this.getNormalized().dot(e.getNormalized()):this.dot(e);return Math.acos(h)},clear:function(){this.x=this.y=0;return this},compareTo:function(){if(this.x==v.x&&
this.y==v.y)return 0;return this.magSquared()-v.magSquared()},constrain:function(e,g){if(e instanceof toxi.Vec2D&&g instanceof toxi.Vec2D){this.x=toxi.MathUtils.clip(this.x,min.x,max.x);this.y=toxi.MathUtils.clip(this.y,min.y,max.y)}else if(e.x!=undefined&&e.y!=undefined&&e.width!=undefined&&e.height!=undefined){this.x=toxi.MathUtils.clip(this.x,e.x,e.x+e.width);this.y=toxi.MathUtils.clip(this.y,e.y,e.y+e.height)}return this},copy:function(){return new toxi.Vec2D(this)},cross:function(e){return this.x*
e.y-this.y*e.x},distanceTo:function(e){if(e!==undefined){var g=this.x-e.x;e=this.y-e.y;return Math.sqrt(g*g+e*e)}else return NaN},distanceToSquared:function(e){if(e!==undefined){var g=this.x-e.x;e=this.y-e.y;return g*g+e*e}else return NaN},dot:function(e){return this.x*e.x+this.y*e.y},equals:function(e){if(e instanceof toxi.Vec2D)return this.x==e.x&&this.y==e.y;return false},equalsWithTolerance:function(e,g){if(toxi.MathUtils.abs(this.x-e.x)<g)if(toxi.MathUtils.abs(this.y-e.y)<g)return true;return false},
-floor:function(){this.x=toxi.MathUtils.floor(this.x);this.y=toxi.MathUtils.floor(this.y);return this},frac:function(){this.x-=toxi.MathUtils.floor(this.x);this.y-=toxi.MathUtils.floor(this.y);return this},getAbs:function(){return(new toxi.Vec2D(this)).abs()},getComponent:function(e){if(e instanceof Number)switch(e){case 0:case 1:e=toxi.Vec2D.Axis.Y}switch(e){case toxi.Vec2D.Axis.X:return this.x;case toxi.Vec2D.Axis.Y:return this.y}return 0},getConstrained:function(e){return(new toxi.Vec2D(this)).constrain(e)},
+floor:function(){this.x=toxi.MathUtils.floor(this.x);this.y=toxi.MathUtils.floor(this.y);return this},frac:function(){this.x-=toxi.MathUtils.floor(this.x);this.y-=toxi.MathUtils.floor(this.y);return this},getAbs:function(){return(new toxi.Vec2D(this)).abs()},getComponent:function(e){if(typeof e=="number")e=e==0?toxi.Vec2D.Axis.X:toxi.Vec2D.Axis.Y;if(e==toxi.Vec2D.Axis.X)return this.x;else if(e==toxi.Vec2D.Axis.Y)return this.y;return 0},getConstrained:function(e){return(new toxi.Vec2D(this)).constrain(e)},
getFloored:function(){return(new toxi.Vec2D(this)).floor()},getFrac:function(){return(new toxi.Vec2D(this)).frac()},getInverted:function(){return new toxi.Vec2D(-this.x,-this.y)},getLimited:function(e){if(this.magSquared()>e*e)return this.getNormalizedTo(e);return new toxi.Vec2D(this)},getNormalized:function(){return(new toxi.Vec2D(this)).normalize()},getNormalizedTo:function(e){return(new toxi.Vec2D(this)).normalizeTo(e)},getPerpendicular:function(){return(new toxi.Vec2D(this)).perpendicular()},
getReciprocal:function(){return this.copy().reciprocal()},getReflected:function(e){return this.copy().reflect(e)},getRotated:function(e){return(new toxi.Vec2D(this)).rotate(e)},getSignum:function(){return(new toxi.Vec2D(this)).signum()},getVector:function(e,g){if(e instanceof toxi.Vec2D){g=e.y;e=e.x}else if(e!=undefined&&g===undefined)g=e;else if(e===undefined)e=0;else if(g===undefined)g=0;return new toxi.Vec2D(e,g)},heading:function(){return Math.atan2(this.y,this.x)},init:function(e,g){if(e instanceof
toxi.Vec2D){g=e.y;e=e.x}else{if(e===undefined)e=0;if(g===undefined)g=0}this.x=e;this.y=g},interpolateTo:function(e,g,h){if(h===undefined)return new toxi.Vec2D(this.x+(e.x-this.x)*g,this.y+(e.y-this.y)*g)},interpolateToSelf:function(e,g,h){if(h===undefined){this.x+=(e.x-this.x)*g;this.y+=(e.y-this.y)*g}else{this.x=h.interpolate(this.x,e.x,g);this.y=h.interpolate(this.y,e.y,g)}return this},invert:function(){this.x*=-1;this.y*=-1;return this},isInCircle:function(e,g){return this.sub(e).magSquared()<=
@@ -45,10 +45,10 @@ g*g},isInRectangle:function(e){if(this.x<e.x||this.x>e.x+e.width)return false;if
toxi.MathUtils.EPS&&Math.abs(this.y)<toxi.MathUtils.EPS},jitter:function(e,g){var h=this.getVector(e,g);this.x+=toxi.MathUtils.normalizedRandom()*h.x;this.y+=toxi.MathUtils.normalizedRandom()*h.y;return this},limit:function(e){if(this.magSquared()>e*e)return this.normalize().scaleSelf(e);return this},magnitude:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},magSquared:function(){return this.x*this.x+this.y*this.y},max:function(e){return new toxi.Vec2D(toxi.MathUtils.max(this.x,e.x),toxi.MathUtils.max(this.y,
e.y))},maxSelf:function(e){this.x=toxi.MathUtils.max(this.x,e.x);this.y=toxi.MathUtils.max(this.y,e.y);return this},min:function(e){return new toxi.Vec2D(toxi.MathUtils.min(this.x,e.x),MathUtils.min(this.y,e.y))},minSelf:function(e){this.x=MathUtils.min(this.x,e.x);this.y=MathUtils.min(this.y,e.y);return this},normalize:function(){var e=this.x*this.x+this.y*this.y;if(e>0){e=1/Math.sqrt(e);this.x*=e;this.y*=e}return this},normalizeTo:function(e){var g=Math.sqrt(this.x*this.x+this.y*this.y);if(g>0){g=
e/g;this.x*=g;this.y*=g}return this},perpendicular:function(){var e=this.x;this.x=-this.y;this.y=e;return this},reciprocal:function(){this.x=1/this.x;this.y=1/this.y;return this},reflect:function(e){return this.set(e.scale(this.dot(e)*2).subSelf(this))},rotate:function(e){var g=Math.cos(e);e=Math.sin(e);var h=g*this.x-e*this.y;this.y=e*this.x+g*this.y;this.x=h;return this},roundToAxis:function(){if(Math.abs(this.x)<0.5)this.x=0;else{this.x=this.x<0?-1:1;this.y=0}if(Math.abs(this.y)<0.5)this.y=0;else{this.y=
-this.y<0?-1:1;this.x=0}return this},scale:function(e){return new toxi.Vec2D(this.x*e,this.y*e)},scale:function(e,g){var h=this.getVector(e,g);return new toxi.Vec2D(this.x*h.x,this.y*h.y)},scaleSelf:function(e,g){var h=this.getVector(e,g);this.x*=h.x;this.y*=h.y;return this},set:function(e,g){var h=this.getVector(e,g);this.x=h.x;this.y=h.y;return this},setComponent:function(e,g){switch(e){case toxi.Vec2D.Axis.X:this.x=g;break;case toxi.Vec2D.Axis.Y:this.y=g}return this},signum:function(){this.x=this.x<
-0?-1:this.x==0?0:1;this.y=this.y<0?-1:this.y==0?0:1;return this},sub:function(e,g){var h=this.getVector(e,g);return new toxi.Vec2D(this.x-h.x,this.y-h.y)},subSelf:function(e,g){var h=this.getVector(e,g);this.x-=h.x;this.y-=h.y;return this},tangentNormalOfEllipse:function(e,g){var h=this.sub(e);return(new toxi.Vec2D(h.x/(g.x*g.x),h.y/(g.y*g.y))).normalize()},toArray:function(){return[this.x,this.y]},toCartesian:function(){var e=this.x*Math.cos(this.y);this.y=this.x*Math.sin(this.y);this.x=e;return this},
+this.y<0?-1:1;this.x=0}return this},scale:function(e){return new toxi.Vec2D(this.x*e,this.y*e)},scale:function(e,g){var h=this.getVector(e,g);return new toxi.Vec2D(this.x*h.x,this.y*h.y)},scaleSelf:function(e,g){var h=this.getVector(e,g);this.x*=h.x;this.y*=h.y;return this},set:function(e,g){var h=this.getVector(e,g);this.x=h.x;this.y=h.y;return this},setComponent:function(e,g){if(e===toxi.Vec2D.Axis.X)this.x=g;else if(e===toxi.Vec2D.Axis.Y)this.y=g;return this},signum:function(){this.x=this.x<0?
+-1:this.x==0?0:1;this.y=this.y<0?-1:this.y==0?0:1;return this},sub:function(e,g){var h=this.getVector(e,g);return new toxi.Vec2D(this.x-h.x,this.y-h.y)},subSelf:function(e,g){var h=this.getVector(e,g);this.x-=h.x;this.y-=h.y;return this},tangentNormalOfEllipse:function(e,g){var h=this.sub(e);return(new toxi.Vec2D(h.x/(g.x*g.x),h.y/(g.y*g.y))).normalize()},toArray:function(){return[this.x,this.y]},toCartesian:function(){var e=this.x*Math.cos(this.y);this.y=this.x*Math.sin(this.y);this.x=e;return this},
toPolar:function(){var e=Math.sqrt(this.x*this.x+this.y*this.y);this.y=Math.atan2(this.y,this.x);this.x=e;return this},toString:function(){return"{x:"+this.x+", y:"+this.y+"}"}};toxi.Vec2D.X_AXIS=new toxi.Vec2D(1,0);toxi.Vec2D.Y_AXIS=new toxi.Vec2D(0,1);toxi.Vec2D.ZERO=new toxi.Vec2D;toxi.Vec2D.MIN_VALUE=new toxi.Vec2D(Number.MIN_VALUE,Number.MIN_VALUE);toxi.Vec2D.MAX_VALUE=new toxi.Vec2D(Number.MAX_VALUE,Number.MAX_VALUE);toxi.Vec2D.fromTheta=function(e){return new toxi.Vec2D(Math.cos(e),Math.sin(e))};
-toxi.Vec2D.max=function(e,g){return new toxi.Vec2D(toxi.MathUtils.max(e.x,g.x),toxi.MathUtils.max(e.y,g.y))};toxi.Vec2D.min=function(e,g){return new toxi.Vec2D(toxi.MathUtils.min(e.x,g.x),toxi.MathUtils.min(e.y,g.y))};toxi.Vec2D.randomVector=function(){return(new toxi.Vec2D(Math.random()*2-1,Math.random()*2-1)).normalize()};toxi.Vec2D.Axis={X:{getVector:function(){return toxi.Vec2D.X_AXIS}},Y:{getVector:function(){return toxi.Vec2D.Y_AXIS}}};toxi.Vec3D=function(e,g,h){this.init(e,g,h)};
+toxi.Vec2D.max=function(e,g){return new toxi.Vec2D(toxi.MathUtils.max(e.x,g.x),toxi.MathUtils.max(e.y,g.y))};toxi.Vec2D.min=function(e,g){return new toxi.Vec2D(toxi.MathUtils.min(e.x,g.x),toxi.MathUtils.min(e.y,g.y))};toxi.Vec2D.randomVector=function(){return(new toxi.Vec2D(Math.random()*2-1,Math.random()*2-1)).normalize()};toxi.Vec3D=function(e,g,h){this.init(e,g,h)};
toxi.Vec3D.prototype={abs:function(){this.x=Math.abs(this.x);this.y=Math.abs(this.y);this.z=Math.abs(this.z);return this},add:function(e,g,h){if(e instanceof toxi.Vec3D)return new toxi.Vec3D(this.x+e.x,this.y+e.y,this.z+e.z);return new toxi.Vec3D(this.x+e,this.y+g,this.z+h)},addSelf:function(e,g,h){if(e!=undefined&&g!=undefined&&h!=undefined){this.x+=e;this.y+=g;this.z+=h}else{this.x+=e.x;this.y+=e.y;this.z+=e.z}return this},angleBetween:function(e,g){var h;h=g?this.getNormalized().dot(e.getNormalized()):
this.dot(e);return Math.acos(h)},clear:function(){this.x=this.y=this.z=0;return this},compareTo:function(e){if(this.x==e.x&&this.y==e.y&&this.z==e.z)return 0;return this.magSquared()-e.magSqaured()},constrain:function(e){if(e instanceof AABB){e.getMax();e.getMin()}this.x=Math.clip(this.x,this.min.x,this.max.x);this.y=toxi.MathUtils.clip(this.y,this.min.y,this.max.y);this.z=toxi.MathUtils.clip(this.z,this.min.z,this.max.z);return this},copy:function(){return new toxi.Vec3D(this)},cross:function(e){return new toxi.Vec3D(this.y*
e.z-e.y*this.z,this.z*e.x-e.z*this.x,this.x*e.y-e.x*this.y)},crossInto:function(e){var g=e.x,h=e.y;e=e.z;result.x=this.y*e-h*this.z;result.y=this.z*g-e*this.x;result.z=this.x*h-g*this.y;return result},crossSelf:function(e){var g=this.y*e.z-e.y*this.z,h=this.z*e.x-e.z*this.x;this.z=e.y-e.x*this.y;this.y=h;this.x=g;return this},distanceTo:function(e){if(e!=undefined){var g=this.x-e.x,h=this.y-e.y;e=this.z-e.z;return Math.sqrt(g*g+h*h+e*e)}return NaN},distanceToSquared:function(e){if(e!=undefined){var g=
@@ -80,21 +80,21 @@ e.b0[n]+g.x*e.b1[n]+h.x*e.b2[n]+k.x*e.b3[n],j.y*e.b0[n]+g.y*e.b1[n]+h.y*e.b2[n]+
1].y-this.coeffA[e-1].y)*this.bi[e])}for(e=this.numP-2;e>0;e--)this.delta[e].set(this.coeffA[e].x+this.delta[e+1].x*this.bi[e],this.coeffA[e].y+this.delta[e+1].y*this.bi[e])},getDecimatedVertices:function(e,g){if(g===undefined)g=true;if(this.vertices===undefined||this.vertices.length<2)this.computeVertices(Spline2D.DEFAULT_RES);for(var h=this.getEstimatedArcLength(),i=[],j=e/h,k=0,n=0;n<1;n+=j){for(var m=n*h;m>=this.arcLenIndex[k];)k++;this.uniform.push(this.vertices[k-1].interpolateTo(this.vertices[k],
(m-this.arcLenIndex[k-1])/(this.arcLenIndex[k]-this.arcLenIndex[k-1])))}g&&i.push(this.vertices[this.vertices.length-1]);return i},getEstimatedArcLength:function(){if(this.arcLenIndex===undefined||this.arcLenIndex!==undefined&&this.arcLenIndex.length!=this.vertices.length)this.arcLenIndex=[];for(var e=0,g=1;g<this.arcLenIndex.length;g++){e+=this.vertices[g-1].distanceTo(this.vertices[g]);this.arcLenIndex[g]=e}return e},getNumPoints:function(){return this.numP},getPointList:function(){return this.pointList},
getTightness:function(){return this.tightness},setPointList:function(e){this.pointList=e.slice(0);return this},setTightness:function(e){this.tightness=e;this.invTightness=1/this.tightness;return this},updateCoefficients:function(){this.numP=this.pointList.length;if(this.points===undefined||this.points!=undefined&&this.points.length!=this.numP){this.coeffA=[];this.delta=[];this.bi=[];for(var e=0;e<this.numP;e++){this.coeffA[e]=new toxi.Vec2D;this.delta[e]=new toxi.Vec2D}this.setTightness(this.tightness)}this.points=
-this.pointList.slice(0)}};toxi.Spline2D.DEFAULT_TIGHTNESS=0.25;toxi.Spline2D.DEFAULT_RES=16;toxi.Ellipse=function(e,g,h,i){this.ellipseInit(e,g,h,i)};toxi.Ellipse.prototype=new toxi.Vec2D;toxi.Ellipse.prototype.constructor=toxi.Ellipse;toxi.Ellipse.prototype.parent=toxi.Vec2D.prototype;toxi.Ellipse.prototype.containsPoint=function(e){var g=this.getFoci();return e.distanceTo(g[0])+e.distanceTo(g[1])<2*MathUtils.max(this.radius.x,this.radius.y)};
-toxi.Ellipse.prototype.getArea=function(){return MathUtils.PI*radius.x*radius.y};toxi.Ellipse.prototype.getCircumference=function(){return Math.sqrt(0.5*this.radius.magSquared())*MathUtils.TWO_PI};toxi.Ellipse.prototype.getFoci=function(){var e=[];if(this.radius.x>this.radius.y){e[0]=this.sub(this.focus,0);e[1]=this.add(this.focus,0)}else{e[0]=this.sub(0,this.focus);e[1]=this.add(0,this.focus)}return e};toxi.Ellipse.prototype.getRadii=function(){return this.radius.copy()};
-toxi.Ellipse.prototype.ellipseInit=function(e,g,h,i){this.radius=new toxi.Vec2D;if(e===undefined){this.parent.init.call(this,0,0);this.setRadii(1,1)}else if(e instanceof toxi.Vec2D){this.parent.init.call(this,e.x,e.y);g instanceof toxi.Vec2D?this.setRadii(g.x,g.y):this.setRadii(g,g)}else if(i===undefined)if(h===undefined){this.parent.init.call(this,0,0);this.setRadii(e,g)}else{this.parent.init.call(this,e,g);this.setRadii(h,h)}else{this.parent.init.call(this,e,g);this.setRadii(h,i)}return this};
-toxi.Ellipse.prototype.setRadii=function(e,g){if(e instanceof toxi.Vec2D){g=e.y;e=e.x}this.radius.set(e,g);this.focus=this.radius.magnitude();return this};toxi.Ellipse.prototype.toPolygon2D=function(e){for(var g=new toxi.Polygon2D,h=MathUtils.TWO_PI/e,i=0;i<e;i++)g.add(toxi.Vec2D.fromTheta(i*h).scaleSelf(this.radius).addSelf(this));return g};
+this.pointList.slice(0)}};toxi.Spline2D.DEFAULT_TIGHTNESS=0.25;toxi.Spline2D.DEFAULT_RES=16;
+toxi.Ellipse=function(e,g,h,i){this.radius=new toxi.Vec2D;if(arguments.length==0){this.parent.init.call(this,0,0);this.setRadii(1,1)}else if(e instanceof toxi.Vec2D){this.parent.init.call(this,e.x,e.y);g instanceof toxi.Vec2D?this.setRadii(g.x,g.y):this.setRadii(g,g)}else if(i===undefined)if(h===undefined){this.parent.init.call(this,0,0);this.setRadii(e,g)}else{this.parent.init.call(this,e,g);this.setRadii(h,h)}else{this.parent.init.call(this,e,g);this.setRadii(h,i)}};toxi.Ellipse.prototype=new toxi.Vec2D;
+toxi.Ellipse.prototype.constructor=toxi.Ellipse;toxi.Ellipse.prototype.parent=toxi.Vec2D.prototype;toxi.Ellipse.prototype.containsPoint=function(e){var g=this.getFoci();return e.distanceTo(g[0])+e.distanceTo(g[1])<2*MathUtils.max(this.radius.x,this.radius.y)};toxi.Ellipse.prototype.getArea=function(){return MathUtils.PI*radius.x*radius.y};toxi.Ellipse.prototype.getCircumference=function(){return Math.sqrt(0.5*this.radius.magSquared())*MathUtils.TWO_PI};
+toxi.Ellipse.prototype.getFoci=function(){var e=[];if(this.radius.x>this.radius.y){e[0]=this.sub(this.focus,0);e[1]=this.add(this.focus,0)}else{e[0]=this.sub(0,this.focus);e[1]=this.add(0,this.focus)}return e};toxi.Ellipse.prototype.getRadii=function(){return this.radius.copy()};toxi.Ellipse.prototype.setRadii=function(e,g){if(e instanceof toxi.Vec2D){g=e.y;e=e.x}this.radius.set(e,g);this.focus=this.radius.magnitude();return this};
+toxi.Ellipse.prototype.toPolygon2D=function(e){for(var g=new toxi.Polygon2D,h=MathUtils.TWO_PI/e,i=0;i<e;i++)g.add(toxi.Vec2D.fromTheta(i*h).scaleSelf(this.radius).addSelf(this));return g};
toxi.Rect=function(e,g,h,i){if(arguments.length===2)if(e instanceof toxi.Vec2D){this.x=e.x;this.y=e.y;this.width=g.x-this.x;this.height=g.y-this.y}else throw Error("toxi.Rect received incorrect parameters");else if(arguments.length===4){this.x=e;this.y=g;this.width=h;this.height=i}else if(arguments.length>0)throw Error("toxi.Rect received incorrect parameters");};toxi.Rect.fromCenterExtent=function(e,g){return new toxi.Rect(e.sub(g),e.add(g))};
toxi.Rect.prototype={containsPoint:function(e){var g=e.x;e=e.y;if(g<this.x||g>=this.x+this.width)return false;if(e<this.y||e>=this.y+this.height)return false;return true},copy:function(){return new toxi.Rect(this.x,this.y,this.width,this.height)},getArea:function(){return this.width*this.height},getAspect:function(){return this.width/this.height},getBottom:function(){return this.y+this.height},getBottomRight:function(){return new toxi.Vec2D(this.x+this.width,this.y+this.height)},getCentroid:function(){return new toxi.Vec2D(this.x+
this.width*0.5,this.y+this.height*0.5)},getDimensions:function(){return new toxi.Vec2D(this.width,this.height)},getEdge:function(e){var g=undefined;switch(e){case 0:g=new toxi.Line2D(new toxi.Vec2D(this.x,this.y),new toxi.Vec2D(this.x+this.width,this.y));break;case 1:g=new toxi.Line2D(new toxi.Vec2D(this.x+this.width,this.y),new toxi.Vec2D(this.x+this.width,this.y+this.height));break;case 2:g=new toxi.Line2D(new toxi.Vec2D(this.x,this.y+this.height),new toxi.Vec2D(this.x+this.width,this.y+this.height));
break;case 3:g=new toxi.Line2D(new toxi.Vec2D(this.x,this.y),new toxi.Vec2D(this.x,this.y+this.height));break;default:throw Error("edge ID needs to be 0...3");}return g},getLeft:function(){return this.x},getRight:function(){return this.x+this.width},getTop:function(){return this.y},getTopLeft:function(){return new toxi.Vec2D(this.x,this.y)},intersectsRay:function(e,g,h){var i=e.getDirection().reciprocal(),j=i.x<0,k=i.y<0,n=this.getTopLeft(),m=this.getBottomRight(),o=j?m:n,r=(o.x-e.x)*i.x;o=j?n:m;
j=(o.x-e.x)*i.x;o=k?n:m;var s=(o.y-e.y)*i.y;o=k?n:m;i=(o.y-e.y)*i.y;if(!(r>i||s>j)){if(s>r)r=s;if(i<j)j=i;if(r<h&&j>g)return e.getPointAtDistance(r)}},intersectsRect:function(e){return!(this.x>e.x+e.width||this.x+this.width<e.x||this.y>e.y+e.height||this.y+this.height<e.y)},scale:function(e){var g=this.getCentroid();this.width*=e;this.height*=e;this.x=g.x-this.width*0.5;this.y=g.y-this.height*0.5;return this},set:function(e,g,h,i){if(arguments.length==-1){this.y=e.y;this.width=e.width;this.height=
e.height;this.x=e.x}else if(arguments.length===4){this.x=e;this.y=g;this.width=h;this.height=i}else throw Error("toxi.Rect set() received wrong parameters");},setDimenions:function(e){this.width=e.x;this.height=e.y;return this},setPosition:function(e){this.x=e.x;this.y=e.y;return this},toPolygon2D:function(){var e=new toxi.Polygon2D;e.add(new toxi.Vec2D(this.x,this.y));e.add(new toxi.Vec2D(this.x+this.width,this.y));e.add(new toxi.Vec2D(this.x+this.width,this.y+this.height));e.add(new toxi.Vec2D(this.x,
-this.y+this.height));return e},toString:function(){return"rect: {x: "+this.x+", y: "+this.y+", width: "+this.width+", height: "+this.height+"}"},union:function(e){var g=MathUtils.max(this.x+this.width,e.x+e.width);this.x=MathUtils.min(this.x,e.x);this.width=g-this.x;g=MathUtils.max(this.y+this.height,e.y+e.height);this.y=MathUtils.min(this.y,e.y);this.height=g-this.y;return this}};toxi.Circle=function(e,g,h){this.circleInit(e,g,h)};toxi.Circle.prototype=new toxi.Ellipse;
-toxi.Circle.prototype.constructor=toxi.Circle;toxi.Circle.prototype.parent=toxi.Ellipse.prototype;toxi.Circle.from2Points=function(e,g){var h=e.interpolateTo(g,0.5),i=h.distanceTo(e);return new toxi.Circle(h,i)};
+this.y+this.height));return e},toString:function(){return"rect: {x: "+this.x+", y: "+this.y+", width: "+this.width+", height: "+this.height+"}"},union:function(e){var g=MathUtils.max(this.x+this.width,e.x+e.width);this.x=MathUtils.min(this.x,e.x);this.width=g-this.x;g=MathUtils.max(this.y+this.height,e.y+e.height);this.y=MathUtils.min(this.y,e.y);this.height=g-this.y;return this}};
+toxi.Circle=function(e,g,h){if(arguments.length==1)e instanceof toxi.Circle?toxi.Ellipse.apply(this,[e,e.radius.x]):toxi.Ellipse.apply(this,[0,0,e]);else arguments.length==2?toxi.Ellipse.apply(this,[e,g]):toxi.Ellipse.apply(this,[e,g,h,h])};toxi.extend(toxi.Circle,toxi.Ellipse);toxi.Circle.from2Points=function(e,g){var h=e.interpolateTo(g,0.5),i=h.distanceTo(e);return new toxi.Circle(h,i)};
toxi.Circle.from3Points=function(e,g,h){var i=undefined,j=g.sub(e),k=h.sub(g);if(toxi.MathUtils.abs(j.x)<=1.0E-7&&toxi.MathUtils.abs(k.y)<=1.0E-7){g=(new toxi.Vec2D(g.x+h.x,e.y+g.y)).scaleSelf(0.5);e=g.distanceTo(e);i=new toxi.Circle(g,e)}else{j=j.y/j.x;k=k.y/k.x;if(toxi.MathUtils.abs(j-k)>1.0E-7&&j!=0){h=(j*k*(e.y-h.y)+k*(e.x+g.x)-j*(g.x+h.x))/(2*(k-j));g=new toxi.Vec2D(h,-(h-(e.x+g.x)/2)/j+(e.y+g.y)/2);e=g.distanceTo(e);i=new toxi.Circle(g,e)}}return i};
toxi.Circle.prototype.containsPoint=function(e){return this.distanceToSquared(e)<=this.radius.x*this.radius.x};toxi.Circle.prototype.getCircumference=function(){return toxi.MathUtils.TWO_PI*this.radius.x};toxi.Circle.prototype.getRadius=function(){return this.radius.x};toxi.Circle.prototype.getTangentPoints=function(e){var g=this.interpolateTo(e,0.5);return this.intersectsCircle(new toxi.Circle(g,g.distanceTo(e)))};
-toxi.Circle.prototype.circleInit=function(e,g,h){if(g===undefined)e instanceof toxi.Circle?this.parent.ellipseInit.call(this,e,e.radius.x):this.parent.ellipseInit.call(this,0,0,e);else h===undefined?this.parent.ellipseInit.call(this,e,g):this.parent.ellipseInit.call(this,e,g,h,h);return this};
toxi.Circle.prototype.intersectsCircle=function(e){var g=null,h=e.sub(this),i=h.magnitude(),j=this.radius.x;e=e.radius.x;if(i<=j+e&&i>=Math.abs(j-e)){e=(j*j-e*e+i*i)/(2*i);i=1/i;g=this.add(h.scale(e*i));j=Math.sqrt(j*j-e*e);h.perpendicular().scaleSelf(j*i);i=g.add(h);h=g.sub(h);g=[i,h]}return g};toxi.Circle.prototype.setRadius=function(e){this.setRadii(e,e);return this};toxi.CircleIntersector=function(e){this.circle=e;this.isec=undefined};
toxi.CircleIntersector.prototype={getIntersectionData:function(){return this.isec},intersectsRay:function(e){this.isec.clear();var g=circle.sub(e),h=g.magSquared();g=g.dot(e.getDirection());var i=circle.getRadius();h=i*i-(h-g*g);if(h>=0){this.isec.isIntersection=true;this.isec.dist=g-Math.sqrt(h);this.isec.pos=e.getPointAtDistance(isec.dist);this.isec.normal=this.isec.pos.sub(this.circle).normalize()}return this.isec.isIntersection}};toxi.Line2D=function(e,g){this.a=e;this.b=g};
toxi.Line2D.prototype={closestPointTo:function(e){var g=this.b.sub(this.a);e=e.sub(this.a).dot(g)/g.magSquared();if(e<0)return this.a.copy();else if(e>1)return this.b.copy();return this.a.add(g.scaleSelf(e))},copy:function(){return new toxi.Line2D(this.a.copy(),this.b.copy())},equals:function(e){if(this==e)return true;if(!(e instanceof toxi.Line2D))return false;return(this.a.equals(e.a)||this.a.equals(e.b))&&(this.b.equals(e.b)||this.b.equals(e.a))},getDirection:function(){return this.b.sub(this.a).normalize()},
@@ -205,5 +205,4 @@ toxi.Line3D.splitIntoSegments=function(e,g,h,i,j){if(i==null)i=[];j&&i.push(e.co
toxi.Line3D.LineIntersection.prototype={getCoefficient:function(){return this.coeff},getLength:function(){if(this.line==null)return null;return this.line.getLength()},getLine:function(){if(this.line==null)return null;return this.line.copy()},getType:function(){return this.type},isIntersectionInside:function(){return this.type==toxi.Line3D.LineIntersection.Type.INTERSECTING&&this.coeff[0]>=0&&this.coeff[0]<=1&&this.coeff[1]>=0&&this.coeff[1]<=1},toString:function(){return"type: "+this.type+" line: "+
this.line}};toxi.Line3D.LineIntersection.Type={};toxi.Line3D.LineIntersection.Type.NON_INTERSECTING=0;toxi.Line3D.LineIntersection.Type.INTERSECTING=1;toxi.Ray2D=function(e,g,h){if(typeof e=="Number"){e=new toxi.Vec2D(e,g);g=h.getNormalized()}else if(e instanceof toxi.Vec2D){e=e;g=g.getNormalized()}else{e=new toxi.Vec2D;g=toxi.Vec2D.Y_AXIS.copy()}this.parent.init.call(this,e);this.dir=g};toxi.Ray2D.prototype=new toxi.Vec2D;toxi.Ray2D.constructor=toxi.Ray2D;toxi.Ray2D.prototype.parent=toxi.Vec2D.prototype;
toxi.Ray2D.prototype.getDirection=function(){return this.dir.copy()};toxi.Ray2D.prototype.getDistanceToPoint=function(e){e=e.sub(this);return e.distanceTo(this.dir.scale(e.dot(this.dir)))};toxi.Ray2D.prototype.getPointAtDistance=function(e){return this.add(this.dir.scale(e))};toxi.Ray2D.prototype.setDirection=function(e){this.dir.set(e).normalize();return this};toxi.Ray2D.prototype.toLine2DWithPointAtDistance=function(e){return new toxi.Line2D(this.copy(),this.getPointAtDistance(e))};
-toxi.Ray2D.prototype.toString=function(){return"origin: "+this.parent.toString.call(this)+" dir: "+this.dir};toxi.IsectData2D=function(e){if(e!==undefined){this.isIntersection=e.isIntersection;this.dist=e.dist;this.pos=e.pos.copy();this.dir=e.dir.copy();this.normal=e.normal.copy()}else this.clear()};
-toxi.IsectData2D.prototype={clear:function(){this.isIntersection=false;this.dist=0;this.pos=new toxi.Vec2D;this.dir=new toxi.Vec2D;this.normal=new toxi.Vec2D},toString:function(){var e="isec: "+this.isIntersection;if(this.isIntersection)e+=" at:"+this.pos+" dist:"+this.dist+" normal:"+this.normal;return e}};
+toxi.Ray2D.prototype.toString=function(){return"origin: "+this.parent.toString.call(this)+" dir: "+this.dir};
View
19 build/toxi-physics2d.js
@@ -1,4 +1,4 @@
-// toxi-physics2d.js r33 - http://github.com/hapticdata/toxiclibsjs
+// toxi-physics2d.js r34 - http://github.com/hapticdata/toxiclibsjs
toxi.physics2d=toxi.physics2d||{};toxi.physics2d.removeItemFrom=function(a,b){var c=b.indexOf(a);if(c>-1)return b.splice(c,1)};toxi.physics2d.VerletParticle2D=function(a,b,c){this.force=new toxi.Vec2D;if(a instanceof toxi.Vec2D)if(a instanceof toxi.physics2d.VerletParticle2D){b=a.y;c=a.weight;a=a.x;this.isLocked=a.isLocked}else{if(b===undefined){b=a.y;c=1}else{c=b;b=a.y}a=a.x}this.isLocked=false;this.init(a,b);this.prev=new toxi.Vec2D(this);this.temp=new toxi.Vec2D;c=c===undefined?1:c;this.setWeight(c)};
toxi.extend(toxi.physics2d.VerletParticle2D,toxi.Vec2D);toxi.physics2d.VerletParticle2D.prototype.addBehavior=function(a,b){if(this.behaviors===undefined)this.behaviors=[];if(a===undefined)throw{name:"TypeError",message:"behavior was undefined"};b=b===undefined?1:b;a.configure(b);this.behaviors.push(a);return this};toxi.physics2d.VerletParticle2D.prototype.addConstraint=function(a){if(this.constraints===undefined)this.constraints=[];this.constraints.push(a);return this};
toxi.physics2d.VerletParticle2D.prototype.addForce=function(a){this.force.addSelf(a);return this};toxi.physics2d.VerletParticle2D.prototype.addVelocity=function(a){this.prev.subSelf(a);return this};toxi.physics2d.VerletParticle2D.prototype.applyBehaviors=function(){if(this.behaviors!==undefined){var a=0;for(a=0;a<this.behaviors.length;a++)this.behaviors[a].applyBehavior(this)}};
@@ -13,15 +13,16 @@ toxi.physics2d.AttractionBehavior.prototype={applyBehavior:function(a){var b=thi
a},setJitter:function(a){this.jitter=a},setRadius:function(a){this.radius=a;this.radiusSquared=a*a},setStrength:function(a){this.strength=a;this.attrStrength=a*this.timeStep}};toxi.physics2d.ConstantForceBehavior=function(a){this.initConstantForceBehavior(a)};
toxi.physics2d.ConstantForceBehavior.prototype={applyBehavior:function(a){a.addForce(this.scaledForce)},configure:function(a){this.timeStep=a;this.setForce(this.force)},getForce:function(){return this.force},initConstantForceBehavior:function(a){this.force=a;this.scaleForce=new toxi.Vec2D;this.timeStep=0},setForce:function(a){this.force=a;this.scaledForce=this.force.scale(this.timeStep)},toString:function(){return"behavior force: "+this.force+" scaledForce: "+this.scaledForce+" timeStep: "+this.timeStep}};
toxi.physics2d.GravityBehavior=function(a){this.initConstantForceBehavior(a)};toxi.physics2d.GravityBehavior.prototype=new toxi.physics2d.ConstantForceBehavior;toxi.physics2d.GravityBehavior.prototype.constructor=toxi.physics2d.GravityBehavior;toxi.physics2d.GravityBehavior.prototype.parent=toxi.physics2d.ConstantForceBehavior.prototype;toxi.physics2d.GravityBehavior.prototype.configure=function(a){this.timeStep=a;this.scaledForce=this.force.scale(a*a)};
-toxi.physics2d.AngularConstraint=function(a,b){if(arguments.length>1){this.theta=b;this.rootPos=new toxi.Vec2D(a)}else{this.rootPos=new toxi.Vec2D;this.theta=a}if(parseInt(this.theta)!=this.theta)this.theta=MathUtils.radians(this.theta)};toxi.physics2d.AngularConstraint.prototype.apply=function(a){var b=a.sub(this.rootPos),c=MathUtils.floor(b.heading()/this.theta)*this.theta;a.set(this.rootPos.add(toxi.Vec2D.fromTheta(c).scaleSelf(b.magnitude())))};
-toxi.physics2d.AxisConstraint=function(a,b){this.axis=a;this.constraint=b};toxi.physics2d.AxisConstraint.prototype.apply=function(a){a.setComponent(this.axis,this.constraint)};toxi.physics2d.CircularConstraint=function(a,b){this.circle=arguments.length==1?a:new toxi.Circle(a,b)};toxi.physics2d.CircularConstraint.prototype.apply=function(a){this.circle.containsPoint(a)&&a.set(this.circle.add(a.sub(this.circle).nomalizeTo(this.circle.getRadius())))};
-toxi.physics2d.MaxConstraint=function(a,b){this.axis=a;this.threshold=b};toxi.physics2d.MaxConstraint.prototype.apply=function(a){a.getComponent(this.axis)>this.threshold&&a.setComponent(this.axis,this.threshold)};toxi.physics2d.MinConstraint=function(a){this.axis=a;this.threshold=threhold};toxi.physics2d.MinConstraint.prototype.apply=function(a){a.getComponent(this.axis)<this.threshold&&a.setComponent(this.axis,this.threshold)};
-toxi.physics2d.RectConstraint=function(a,b){if(arguments.length==1)this.rect=a.copy();else if(arguments.lengt>1)this.rect=new toxi.Rect(a,b);this.intersectRay=new toxi.Ray2D(this.rect.getCentroid(),new toxi.Vec2D)};toxi.physics2d.RectConstraint.prototype={apply:function(a){this.rect.containsPoint(a)&&a.set(this.rect.intersectsRay(this.intersectRay.setDirection(this.intersectRay.sub(a)),0,Number.MAX_VALUE))},getBox:function(){return this.rect.copy()},setBox:function(a){this.rect=a.copy();this.intersectRay.set(this.rect.getCentroid())}};
-toxi.physics2d.ParticlePath2D=function(a){toxi.Spline2D.call(this,a);this.particles=[]};toxi.extend(toxi.physics2d.ParticlePath2D,toxi.Spline2D);(function(){toxi.physics2d.ParticlePath2D.prototype.createParticles=function(a,b,c,d){this.particles=[];this.computeVertices(b);b=0;c=this.getDecimatedVertices(c,true);for(b=0;b<c;b++){var f=this.createSingleParticle(v,d);this.particles.push(f);a.addParticle(f)}return this.particles}})();
-toxi.physics2d.ParticleString2D=function(a,b,c,d,f,j){this.physics=a;this.links=[];var g=undefined,e=undefined,i=undefined,h=0;if(arguments.length===3){j=c;this.particles=b||[];for(h=0;h<this.particles.length;h++){e=this.particles[h];this.physics.addParticle(e);if(g!==undefined){i=this.createSpring(g,e,g.distanceTo(e),stregnth_step);this.links.push(i);this.physics.addSpring(i)}g=e}}else{var k=b.copy(),l=c.magnitude();this.particles=[];for(h=0;h<d;h++){e=new toxi.physics2d.VerletParticle2D(k.copy(),
-f);this.particles.push(e);this.physics.particles.push(e);if(g!==undefined){i=this.createSpring(g,e,l,j);this.links.push(i);this.physics.addSpring(i)}g=e;k.addSelf(c)}}};
+toxi.physics2d.AngularConstraint=function(a,b){if(arguments.length>1){this.theta=b;this.rootPos=new toxi.Vec2D(a)}else{this.rootPos=new toxi.Vec2D;this.theta=a}if(parseInt(this.theta)!=this.theta)this.theta=toxi.MathUtils.radians(this.theta)};toxi.physics2d.AngularConstraint.prototype.applyConstraint=function(a){var b=a.sub(this.rootPos),c=toxi.MathUtils.floor(b.heading()/this.theta)*this.theta;a.set(this.rootPos.add(toxi.Vec2D.fromTheta(c).scaleSelf(b.magnitude())))};
+toxi.physics2d.AxisConstraint=function(a,b){this.axis=a;this.constraint=b};toxi.physics2d.AxisConstraint.prototype.applyConstraint=function(a){a.setComponent(this.axis,this.constraint)};toxi.physics2d.CircularConstraint=function(a,b){if(arguments.length==1)this.circle=a;else{console.log("a: "+a);this.circle=new toxi.Circle(a,b)}};toxi.physics2d.CircularConstraint.prototype.applyConstraint=function(a){this.circle.containsPoint(a)&&a.set(this.circle.add(a.sub(this.circle).normalizeTo(this.circle.getRadius())))};
+toxi.physics2d.MaxConstraint=function(a,b){this.axis=a;this.threshold=b};toxi.physics2d.MaxConstraint.prototype.applyConstraint=function(a){a.getComponent(this.axis)>this.threshold&&a.setComponent(this.axis,this.threshold)};toxi.physics2d.MinConstraint=function(a,b){this.axis=a;this.threshold=b};toxi.physics2d.MinConstraint.prototype.applyConstraint=function(a){a.getComponent(this.axis)<this.threshold&&a.setComponent(this.axis,this.threshold)};
+toxi.physics2d.RectConstraint=function(a,b){if(arguments.length==1)this.rect=a.copy();else if(arguments.length>1)this.rect=new toxi.Rect(a,b);this.intersectRay=new toxi.Ray2D(this.rect.getCentroid(),new toxi.Vec2D)};
+toxi.physics2d.RectConstraint.prototype={applyConstraint:function(a){this.rect.containsPoint(a)&&a.set(this.rect.intersectsRay(this.intersectRay.setDirection(this.intersectRay.sub(a)),0,Number.MAX_VALUE))},getBox:function(){return this.rect.copy()},setBox:function(a){this.rect=a.copy();this.intersectRay.set(this.rect.getCentroid())}};toxi.physics2d.ParticlePath2D=function(a){toxi.Spline2D.call(this,a);this.particles=[]};toxi.extend(toxi.physics2d.ParticlePath2D,toxi.Spline2D);
+(function(){toxi.physics2d.ParticlePath2D.prototype.createParticles=function(a,b,c,d){this.particles=[];this.computeVertices(b);b=0;c=this.getDecimatedVertices(c,true);for(b=0;b<c;b++){var f=this.createSingleParticle(v,d);this.particles.push(f);a.addParticle(f)}return this.particles}})();
+toxi.physics2d.ParticleString2D=function(a,b,c,d,f,j){this.physics=a;this.links=[];var g=undefined,e=undefined,i=undefined,h=0;if(arguments.length===3){j=c;this.particles=b||[];for(h=0;h<this.particles.length;h++){e=this.particles[h];this.physics.addParticle(e);if(g!==undefined){i=this.createSpring(g,e,g.distanceTo(e),c);this.links.push(i);this.physics.addSpring(i)}g=e}}else{var k=b.copy(),l=c.magnitude();this.particles=[];for(h=0;h<d;h++){e=new toxi.physics2d.VerletParticle2D(k.copy(),f);this.particles.push(e);
+this.physics.particles.push(e);if(g!==undefined){i=this.createSpring(g,e,l,j);this.links.push(i);this.physics.addSpring(i)}g=e;k.addSelf(c)}}};
toxi.physics2d.ParticleString2D.prototype={clear:function(){for(var a=0,b=this.links.length;a<b;a++)this.physics.removeSpringElements(s);this.particles.clear();this.links.clear()},createSpring:function(a,b,c,d){return new toxi.physics2d.VerletSpring2D(a,b,c,d)},getHead:function(){return this.particles[0]},getNumParticles:function(){return this.particles.length},getTail:function(){return this.particles[this.particles.length-1]}};
-toxi.physics2d.PullBackString2D=function(a,b,c){toxi.physics2d.VerletSpring2D.call(this,a,b,c);a.lock();this.setRestLength(0.5)};toxi.extend(toxi.physics2d.PullBackString2D,toxi.physics2d.VerletSpring2D);toxi.physics2d.PullBackString2D.prototype.update=function(a){this.b.distanceToSquared(this.a)>this.restLengthSquared&&this.parent.update.call(this,a)};
+toxi.physics2d.PullBackString2D=function(a,b,c){toxi.physics2d.VerletSpring2D.call(this,a,b,0,c);a.lock();this.setRestLength(0.5)};toxi.extend(toxi.physics2d.PullBackString2D,toxi.physics2d.VerletSpring2D);toxi.physics2d.PullBackString2D.prototype.update=function(a){this.b.distanceToSquared(this.a)>this.restLengthSquared&&this.parent.update.call(this,a)};
toxi.physics2d.VerletConstrainedSpring2D=function(a,b,c,d,f){toxi.physics2d.VerletSpring2D.call(this,a,b,c,d);this.limit=f===undefined?Number.MAX_VALUE:f};toxi.extend(toxi.physics2d.VerletConstrainedSpring2D,toxi.physics2d.VerletSpring2D);
toxi.physics2d.VerletConstrainedSpring2D.update=function(a){var b=this.b.sub(this.a),c=b.magnitude()+toxi.physics2d.VerletSpring2D.EPS;c=(c-this.restLength)/(c*(this.a.invWeight+this.b.invWeight))*this.strength;if(!this.a.isLocked&&!this.isALocked){this.a.addSelf(b.scale(c*this.a.invWeight).limit(this.limit));a&&this.a.applyConstraints()}if(!this.b.isLocked&&!this.isBLocked){this.b.subSelf(b.scale(c*this.b.invWeight).limit(this.limit));a&&this.b.applyConstraints()}};
toxi.physics2d.VerletMinDistanceSpring2D=function(a,b,c,d){toxi.physics2d.VerletSpring2D.call(this,a,b,c,d);this.setRestLength(c)};toxi.extend(toxi.physics2d.VerletMinDistanceSpring2D,toxi.physics2d.VerletSpring2D);toxi.physics2d.VerletMinDistanceSpring2D.prototype.update=function(a){this.b.distanceToSquared(this.a)<this.restLengthSquared&&this.parent.update.call(this,a)};
View
47 build/toxiclibs.js
@@ -1,4 +1,4 @@
-// toxiclibs.js r33 - http://github.com/hapticdata/toxiclibsjs
+// toxiclibs.js r34 - http://github.com/hapticdata/toxiclibsjs
var toxi=toxi||{};toxi.extend=function(e,g){e.prototype=new g;e.constructor=e;e.prototype.parent=g.prototype};toxi.MathUtils={};toxi.MathUtils.SQRT2=Math.sqrt(2);toxi.MathUtils.SQRT3=Math.sqrt(3);toxi.MathUtils.LOG2=Math.log(2);toxi.MathUtils.PI=3.141592653589793;toxi.MathUtils.INV_PI=1/toxi.MathUtils.PI;toxi.MathUtils.HALF_PI=toxi.MathUtils.PI/2;toxi.MathUtils.THIRD_PI=toxi.MathUtils.PI/3;toxi.MathUtils.QUARTER_PI=toxi.MathUtils.PI/4;toxi.MathUtils.TWO_PI=toxi.MathUtils.PI*2;
toxi.MathUtils.THREE_HALVES_PI=toxi.MathUtils.TWO_PI-toxi.MathUtils.HALF_PI;toxi.MathUtils.PI_SQUARED=toxi.MathUtils.PI*toxi.MathUtils.PI;toxi.MathUtils.EPS=1.1920928955078125E-7;toxi.MathUtils.DEG2RAD=toxi.MathUtils.PI/180;toxi.MathUtils.RAD2DEG=180/toxi.MathUtils.PI;toxi.MathUtils.SHIFT23=8388608;toxi.MathUtils.INV_SHIFT23=1/toxi.MathUtils.SHIFT23;toxi.MathUtils.SIN_A=-4/(toxi.MathUtils.PI*toxi.MathUtils.PI);toxi.MathUtils.SIN_B=4/toxi.MathUtils.PI;toxi.MathUtils.SIN_P=0.225;
toxi.MathUtils.abs=Math.abs;toxi.MathUtils.ceilPowerOf2=function(e){for(var g=1;g<e;)g<<=1;return g};toxi.MathUtils.clip=function(e,g,h){return e<g?g:e>h?h:e};toxi.MathUtils.clipNormalized=function(e){if(e<0)return 0;else if(e>1)return 1;return e};toxi.MathUtils.cos=Math.cos;toxi.MathUtils.fastCos=function(e){return toxi.MathUtils.fastSin(e+(e>toxi.MathUtils.HALF_PI?-toxi.MathUtils.THREE_HALVES_PI:toxi.MathUtils.HALF_PI))};
@@ -33,11 +33,11 @@ toxi.FMTriangleWave.prototype.pop=function(){this.parent.pop.call(this);this.fmo
toxi.SineWave=function(e,g,h,i){this.parent.init.call(this,e,g,h,i)};toxi.SineWave.prototype=new toxi.AbstractWave;toxi.SineWave.constructor=toxi.SineWave;toxi.SineWave.prototype.parent=toxi.AbstractWave.prototype;toxi.SineWave.prototype.getClass=function(){return"SineWave"};toxi.SineWave.prototype.pop=function(){this.parent.pop.call(this)};toxi.SineWave.prototype.push=function(){this.parent.push.call(this)};
toxi.SineWave.prototype.update=function(){this.value=Math.sin(this.phase)*this.amp+this.offset;this.cyclePhase(this.frequency);return this.value};toxi.WaveState=function(e,g,h,i){this.phase=e;this.frequency=g;this.amp=h;this.offset=i};toxi.SinCosLUT=function(e){this.precision=e;this.period=360/this.precision;this.quadrant=this.period>>2;this.deg2rad=Math.PI/180*this.precision;this.rad2deg=180/Math.PI/this.precision;this.sinLUT=[];for(e=0;e<this.period;e++)this.sinLUT[e]=Math.sin(e*this.deg2rad)};
toxi.SinCosLUT.prototype={cos:function(e){for(;e<0;)e+=toxi.MathUtils.TWO_PI;return this.sinLUT[(e*this.rad2deg+this.quadrant)%this.period]},getPeriod:function(){return this.period},getPrecision:function(){return this.precision},getSinLUT:function(){return this.sinLUT},sin:function(e){for(;e<0;)e+=toxi.MathUtils.TWO_PI;return this.sinLUT[e*this.rad2deg%this.period]}};toxi.SinCosLUT.DEFAULT_PRECISION=0.25;toxi.SinCosLUT.DEFAULT_INSTANCE=null;
-toxi.SinCosLUT.getDefaultInstance=function(){if(toxi.SinCosLUT.DEFAULT_INSTANCE==null)toxi.SinCosLUT.DEFAULT_INSTANCE=new toxi.SinCosLUT;return toxi.SinCosLUT.DEFAULT_INSTANCE};toxi.Vec2D=function(e,g){this.init(e,g)};
+toxi.SinCosLUT.getDefaultInstance=function(){if(toxi.SinCosLUT.DEFAULT_INSTANCE==null)toxi.SinCosLUT.DEFAULT_INSTANCE=new toxi.SinCosLUT;return toxi.SinCosLUT.DEFAULT_INSTANCE};toxi.Vec2D=function(e,g){this.init(e,g)};toxi.Vec2D.Axis={X:{getVector:function(){return toxi.Vec2D.X_AXIS},toString:function(){return"toxi.Vec2D.Axis.X"}},Y:{getVector:function(){return toxi.Vec2D.Y_AXIS},toString:function(){return"toxi.Vec2D.Axis.Y"}}};
toxi.Vec2D.prototype={abs:function(){this.x=Math.abs(this.x);this.y=Math.abs(this.y);return this},add:function(e,g){var h=this.getVector(e,g);return new toxi.Vec2D(this.x+h.x,this.y+h.y)},addSelf:function(e,g){var h=this.getVector(e,g);this.x+=h.x;this.y+=h.y;return this},angleBetween:function(e,g){var h;h=g!==undefined&&faceNormalize==true?this.getNormalized().dot(e.getNormalized()):this.dot(e);return Math.acos(h)},clear:function(){this.x=this.y=0;return this},compareTo:function(){if(this.x==v.x&&
this.y==v.y)return 0;return this.magSquared()-v.magSquared()},constrain:function(e,g){if(e instanceof toxi.Vec2D&&g instanceof toxi.Vec2D){this.x=toxi.MathUtils.clip(this.x,min.x,max.x);this.y=toxi.MathUtils.clip(this.y,min.y,max.y)}else if(e.x!=undefined&&e.y!=undefined&&e.width!=undefined&&e.height!=undefined){this.x=toxi.MathUtils.clip(this.x,e.x,e.x+e.width);this.y=toxi.MathUtils.clip(this.y,e.y,e.y+e.height)}return this},copy:function(){return new toxi.Vec2D(this)},cross:function(e){return this.x*
e.y-this.y*e.x},distanceTo:function(e){if(e!==undefined){var g=this.x-e.x;e=this.y-e.y;return Math.sqrt(g*g+e*e)}else return NaN},distanceToSquared:function(e){if(e!==undefined){var g=this.x-e.x;e=this.y-e.y;return g*g+e*e}else return NaN},dot:function(e){return this.x*e.x+this.y*e.y},equals:function(e){if(e instanceof toxi.Vec2D)return this.x==e.x&&this.y==e.y;return false},equalsWithTolerance:function(e,g){if(toxi.MathUtils.abs(this.x-e.x)<g)if(toxi.MathUtils.abs(this.y-e.y)<g)return true;return false},
-floor:function(){this.x=toxi.MathUtils.floor(this.x);this.y=toxi.MathUtils.floor(this.y);return this},frac:function(){this.x-=toxi.MathUtils.floor(this.x);this.y-=toxi.MathUtils.floor(this.y);return this},getAbs:function(){return(new toxi.Vec2D(this)).abs()},getComponent:function(e){if(e instanceof Number)switch(e){case 0:case 1:e=toxi.Vec2D.Axis.Y}switch(e){case toxi.Vec2D.Axis.X:return this.x;case toxi.Vec2D.Axis.Y:return this.y}return 0},getConstrained:function(e){return(new toxi.Vec2D(this)).constrain(e)},
+floor:function(){this.x=toxi.MathUtils.floor(this.x);this.y=toxi.MathUtils.floor(this.y);return this},frac:function(){this.x-=toxi.MathUtils.floor(this.x);this.y-=toxi.MathUtils.floor(this.y);return this},getAbs:function(){return(new toxi.Vec2D(this)).abs()},getComponent:function(e){if(typeof e=="number")e=e==0?toxi.Vec2D.Axis.X:toxi.Vec2D.Axis.Y;if(e==toxi.Vec2D.Axis.X)return this.x;else if(e==toxi.Vec2D.Axis.Y)return this.y;return 0},getConstrained:function(e){return(new toxi.Vec2D(this)).constrain(e)},
getFloored:function(){return(new toxi.Vec2D(this)).floor()},getFrac:function(){return(new toxi.Vec2D(this)).frac()},getInverted:function(){return new toxi.Vec2D(-this.x,-this.y)},getLimited:function(e){if(this.magSquared()>e*e)return this.getNormalizedTo(e);return new toxi.Vec2D(this)},getNormalized:function(){return(new toxi.Vec2D(this)).normalize()},getNormalizedTo:function(e){return(new toxi.Vec2D(this)).normalizeTo(e)},getPerpendicular:function(){return(new toxi.Vec2D(this)).perpendicular()},
getReciprocal:function(){return this.copy().reciprocal()},getReflected:function(e){return this.copy().reflect(e)},getRotated:function(e){return(new toxi.Vec2D(this)).rotate(e)},getSignum:function(){return(new toxi.Vec2D(this)).signum()},getVector:function(e,g){if(e instanceof toxi.Vec2D){g=e.y;e=e.x}else if(e!=undefined&&g===undefined)g=e;else if(e===undefined)e=0;else if(g===undefined)g=0;return new toxi.Vec2D(e,g)},heading:function(){return Math.atan2(this.y,this.x)},init:function(e,g){if(e instanceof
toxi.Vec2D){g=e.y;e=e.x}else{if(e===undefined)e=0;if(g===undefined)g=0}this.x=e;this.y=g},interpolateTo:function(e,g,h){if(h===undefined)return new toxi.Vec2D(this.x+(e.x-this.x)*g,this.y+(e.y-this.y)*g)},interpolateToSelf:function(e,g,h){if(h===undefined){this.x+=(e.x-this.x)*g;this.y+=(e.y-this.y)*g}else{this.x=h.interpolate(this.x,e.x,g);this.y=h.interpolate(this.y,e.y,g)}return this},invert:function(){this.x*=-1;this.y*=-1;return this},isInCircle:function(e,g){return this.sub(e).magSquared()<=
@@ -45,10 +45,10 @@ g*g},isInRectangle:function(e){if(this.x<e.x||this.x>e.x+e.width)return false;if
toxi.MathUtils.EPS&&Math.abs(this.y)<toxi.MathUtils.EPS},jitter:function(e,g){var h=this.getVector(e,g);this.x+=toxi.MathUtils.normalizedRandom()*h.x;this.y+=toxi.MathUtils.normalizedRandom()*h.y;return this},limit:function(e){if(this.magSquared()>e*e)return this.normalize().scaleSelf(e);return this},magnitude:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},magSquared:function(){return this.x*this.x+this.y*this.y},max:function(e){return new toxi.Vec2D(toxi.MathUtils.max(this.x,e.x),toxi.MathUtils.max(this.y,
e.y))},maxSelf:function(e){this.x=toxi.MathUtils.max(this.x,e.x);this.y=toxi.MathUtils.max(this.y,e.y);return this},min:function(e){return new toxi.Vec2D(toxi.MathUtils.min(this.x,e.x),MathUtils.min(this.y,e.y))},minSelf:function(e){this.x=MathUtils.min(this.x,e.x);this.y=MathUtils.min(this.y,e.y);return this},normalize:function(){var e=this.x*this.x+this.y*this.y;if(e>0){e=1/Math.sqrt(e);this.x*=e;this.y*=e}return this},normalizeTo:function(e){var g=Math.sqrt(this.x*this.x+this.y*this.y);if(g>0){g=
e/g;this.x*=g;this.y*=g}return this},perpendicular:function(){var e=this.x;this.x=-this.y;this.y=e;return this},reciprocal:function(){this.x=1/this.x;this.y=1/this.y;return this},reflect:function(e){return this.set(e.scale(this.dot(e)*2).subSelf(this))},rotate:function(e){var g=Math.cos(e);e=Math.sin(e);var h=g*this.x-e*this.y;this.y=e*this.x+g*this.y;this.x=h;return this},roundToAxis:function(){if(Math.abs(this.x)<0.5)this.x=0;else{this.x=this.x<0?-1:1;this.y=0}if(Math.abs(this.y)<0.5)this.y=0;else{this.y=
-this.y<0?-1:1;this.x=0}return this},scale:function(e){return new toxi.Vec2D(this.x*e,this.y*e)},scale:function(e,g){var h=this.getVector(e,g);return new toxi.Vec2D(this.x*h.x,this.y*h.y)},scaleSelf:function(e,g){var h=this.getVector(e,g);this.x*=h.x;this.y*=h.y;return this},set:function(e,g){var h=this.getVector(e,g);this.x=h.x;this.y=h.y;return this},setComponent:function(e,g){switch(e){case toxi.Vec2D.Axis.X:this.x=g;break;case toxi.Vec2D.Axis.Y:this.y=g}return this},signum:function(){this.x=this.x<
-0?-1:this.x==0?0:1;this.y=this.y<0?-1:this.y==0?0:1;return this},sub:function(e,g){var h=this.getVector(e,g);return new toxi.Vec2D(this.x-h.x,this.y-h.y)},subSelf:function(e,g){var h=this.getVector(e,g);this.x-=h.x;this.y-=h.y;return this},tangentNormalOfEllipse:function(e,g){var h=this.sub(e);return(new toxi.Vec2D(h.x/(g.x*g.x),h.y/(g.y*g.y))).normalize()},toArray:function(){return[this.x,this.y]},toCartesian:function(){var e=this.x*Math.cos(this.y);this.y=this.x*Math.sin(this.y);this.x=e;return this},
+this.y<0?-1:1;this.x=0}return this},scale:function(e){return new toxi.Vec2D(this.x*e,this.y*e)},scale:function(e,g){var h=this.getVector(e,g);return new toxi.Vec2D(this.x*h.x,this.y*h.y)},scaleSelf:function(e,g){var h=this.getVector(e,g);this.x*=h.x;this.y*=h.y;return this},set:function(e,g){var h=this.getVector(e,g);this.x=h.x;this.y=h.y;return this},setComponent:function(e,g){if(e===toxi.Vec2D.Axis.X)this.x=g;else if(e===toxi.Vec2D.Axis.Y)this.y=g;return this},signum:function(){this.x=this.x<0?
+-1:this.x==0?0:1;this.y=this.y<0?-1:this.y==0?0:1;return this},sub:function(e,g){var h=this.getVector(e,g);return new toxi.Vec2D(this.x-h.x,this.y-h.y)},subSelf:function(e,g){var h=this.getVector(e,g);this.x-=h.x;this.y-=h.y;return this},tangentNormalOfEllipse:function(e,g){var h=this.sub(e);return(new toxi.Vec2D(h.x/(g.x*g.x),h.y/(g.y*g.y))).normalize()},toArray:function(){return[this.x,this.y]},toCartesian:function(){var e=this.x*Math.cos(this.y);this.y=this.x*Math.sin(this.y);this.x=e;return this},
toPolar:function(){var e=Math.sqrt(this.x*this.x+this.y*this.y);this.y=Math.atan2(this.y,this.x);this.x=e;return this},toString:function(){return"{x:"+this.x+", y:"+this.y+"}"}};toxi.Vec2D.X_AXIS=new toxi.Vec2D(1,0);toxi.Vec2D.Y_AXIS=new toxi.Vec2D(0,1);toxi.Vec2D.ZERO=new toxi.Vec2D;toxi.Vec2D.MIN_VALUE=new toxi.Vec2D(Number.MIN_VALUE,Number.MIN_VALUE);toxi.Vec2D.MAX_VALUE=new toxi.Vec2D(Number.MAX_VALUE,Number.MAX_VALUE);toxi.Vec2D.fromTheta=function(e){return new toxi.Vec2D(Math.cos(e),Math.sin(e))};
-toxi.Vec2D.max=function(e,g){return new toxi.Vec2D(toxi.MathUtils.max(e.x,g.x),toxi.MathUtils.max(e.y,g.y))};toxi.Vec2D.min=function(e,g){return new toxi.Vec2D(toxi.MathUtils.min(e.x,g.x),toxi.MathUtils.min(e.y,g.y))};toxi.Vec2D.randomVector=function(){return(new toxi.Vec2D(Math.random()*2-1,Math.random()*2-1)).normalize()};toxi.Vec2D.Axis={X:{getVector:function(){return toxi.Vec2D.X_AXIS}},Y:{getVector:function(){return toxi.Vec2D.Y_AXIS}}};toxi.Vec3D=function(e,g,h){this.init(e,g,h)};
+toxi.Vec2D.max=function(e,g){return new toxi.Vec2D(toxi.MathUtils.max(e.x,g.x),toxi.MathUtils.max(e.y,g.y))};toxi.Vec2D.min=function(e,g){return new toxi.Vec2D(toxi.MathUtils.min(e.x,g.x),toxi.MathUtils.min(e.y,g.y))};toxi.Vec2D.randomVector=function(){return(new toxi.Vec2D(Math.random()*2-1,Math.random()*2-1)).normalize()};toxi.Vec3D=function(e,g,h){this.init(e,g,h)};
toxi.Vec3D.prototype={abs:function(){this.x=Math.abs(this.x);this.y=Math.abs(this.y);this.z=Math.abs(this.z);return this},add:function(e,g,h){if(e instanceof toxi.Vec3D)return new toxi.Vec3D(this.x+e.x,this.y+e.y,this.z+e.z);return new toxi.Vec3D(this.x+e,this.y+g,this.z+h)},addSelf:function(e,g,h){if(e!=undefined&&g!=undefined&&h!=undefined){this.x+=e;this.y+=g;this.z+=h}else{this.x+=e.x;this.y+=e.y;this.z+=e.z}return this},angleBetween:function(e,g){var h;h=g?this.getNormalized().dot(e.getNormalized()):
this.dot(e);return Math.acos(h)},clear:function(){this.x=this.y=this.z=0;return this},compareTo:function(e){if(this.x==e.x&&this.y==e.y&&this.z==e.z)return 0;return this.magSquared()-e.magSqaured()},constrain:function(e){if(e instanceof AABB){e.getMax();e.getMin()}this.x=Math.clip(this.x,this.min.x,this.max.x);this.y=toxi.MathUtils.clip(this.y,this.min.y,this.max.y);this.z=toxi.MathUtils.clip(this.z,this.min.z,this.max.z);return this},copy:function(){return new toxi.Vec3D(this)},cross:function(e){return new toxi.Vec3D(this.y*
e.z-e.y*this.z,this.z*e.x-e.z*this.x,this.x*e.y-e.x*this.y)},crossInto:function(e){var g=e.x,h=e.y;e=e.z;result.x=this.y*e-h*this.z;result.y=this.z*g-e*this.x;result.z=this.x*h-g*this.y;return result},crossSelf:function(e){var g=this.y*e.z-e.y*this.z,h=this.z*e.x-e.z*this.x;this.z=e.y-e.x*this.y;this.y=h;this.x=g;return this},distanceTo:function(e){if(e!=undefined){var g=this.x-e.x,h=this.y-e.y;e=this.z-e.z;return Math.sqrt(g*g+h*h+e*e)}return NaN},distanceToSquared:function(e){if(e!=undefined){var g=
@@ -80,21 +80,21 @@ e.b0[n]+g.x*e.b1[n]+h.x*e.b2[n]+k.x*e.b3[n],j.y*e.b0[n]+g.y*e.b1[n]+h.y*e.b2[n]+
1].y-this.coeffA[e-1].y)*this.bi[e])}for(e=this.numP-2;e>0;e--)this.delta[e].set(this.coeffA[e].x+this.delta[e+1].x*this.bi[e],this.coeffA[e].y+this.delta[e+1].y*this.bi[e])},getDecimatedVertices:function(e,g){if(g===undefined)g=true;if(this.vertices===undefined||this.vertices.length<2)this.computeVertices(Spline2D.DEFAULT_RES);for(var h=this.getEstimatedArcLength(),i=[],j=e/h,k=0,n=0;n<1;n+=j){for(var m=n*h;m>=this.arcLenIndex[k];)k++;this.uniform.push(this.vertices[k-1].interpolateTo(this.vertices[k],
(m-this.arcLenIndex[k-1])/(this.arcLenIndex[k]-this.arcLenIndex[k-1])))}g&&i.push(this.vertices[this.vertices.length-1]);return i},getEstimatedArcLength:function(){if(this.arcLenIndex===undefined||this.arcLenIndex!==undefined&&this.arcLenIndex.length!=this.vertices.length)this.arcLenIndex=[];for(var e=0,g=1;g<this.arcLenIndex.length;g++){e+=this.vertices[g-1].distanceTo(this.vertices[g]);this.arcLenIndex[g]=e}return e},getNumPoints:function(){return this.numP},getPointList:function(){return this.pointList},
getTightness:function(){return this.tightness},setPointList:function(e){this.pointList=e.slice(0);return this},setTightness:function(e){this.tightness=e;this.invTightness=1/this.tightness;return this},updateCoefficients:function(){this.numP=this.pointList.length;if(this.points===undefined||this.points!=undefined&&this.points.length!=this.numP){this.coeffA=[];this.delta=[];this.bi=[];for(var e=0;e<this.numP;e++){this.coeffA[e]=new toxi.Vec2D;this.delta[e]=new toxi.Vec2D}this.setTightness(this.tightness)}this.points=
-this.pointList.slice(0)}};toxi.Spline2D.DEFAULT_TIGHTNESS=0.25;toxi.Spline2D.DEFAULT_RES=16;toxi.Ellipse=function(e,g,h,i){this.ellipseInit(e,g,h,i)};toxi.Ellipse.prototype=new toxi.Vec2D;toxi.Ellipse.prototype.constructor=toxi.Ellipse;toxi.Ellipse.prototype.parent=toxi.Vec2D.prototype;toxi.Ellipse.prototype.containsPoint=function(e){var g=this.getFoci();return e.distanceTo(g[0])+e.distanceTo(g[1])<2*MathUtils.max(this.radius.x,this.radius.y)};
-toxi.Ellipse.prototype.getArea=function(){return MathUtils.PI*radius.x*radius.y};toxi.Ellipse.prototype.getCircumference=function(){return Math.sqrt(0.5*this.radius.magSquared())*MathUtils.TWO_PI};toxi.Ellipse.prototype.getFoci=function(){var e=[];if(this.radius.x>this.radius.y){e[0]=this.sub(this.focus,0);e[1]=this.add(this.focus,0)}else{e[0]=this.sub(0,this.focus);e[1]=this.add(0,this.focus)}return e};toxi.Ellipse.prototype.getRadii=function(){return this.radius.copy()};
-toxi.Ellipse.prototype.ellipseInit=function(e,g,h,i){this.radius=new toxi.Vec2D;if(e===undefined){this.parent.init.call(this,0,0);this.setRadii(1,1)}else if(e instanceof toxi.Vec2D){this.parent.init.call(this,e.x,e.y);g instanceof toxi.Vec2D?this.setRadii(g.x,g.y):this.setRadii(g,g)}else if(i===undefined)if(h===undefined){this.parent.init.call(this,0,0);this.setRadii(e,g)}else{this.parent.init.call(this,e,g);this.setRadii(h,h)}else{this.parent.init.call(this,e,g);this.setRadii(h,i)}return this};
-toxi.Ellipse.prototype.setRadii=function(e,g){if(e instanceof toxi.Vec2D){g=e.y;e=e.x}this.radius.set(e,g);this.focus=this.radius.magnitude();return this};toxi.Ellipse.prototype.toPolygon2D=function(e){for(var g=new toxi.Polygon2D,h=MathUtils.TWO_PI/e,i=0;i<e;i++)g.add(toxi.Vec2D.fromTheta(i*h).scaleSelf(this.radius).addSelf(this));return g};
+this.pointList.slice(0)}};toxi.Spline2D.DEFAULT_TIGHTNESS=0.25;toxi.Spline2D.DEFAULT_RES=16;
+toxi.Ellipse=function(e,g,h,i){this.radius=new toxi.Vec2D;if(arguments.length==0){this.parent.init.call(this,0,0);this.setRadii(1,1)}else if(e instanceof toxi.Vec2D){this.parent.init.call(this,e.x,e.y);g instanceof toxi.Vec2D?this.setRadii(g.x,g.y):this.setRadii(g,g)}else if(i===undefined)if(h===undefined){this.parent.init.call(this,0,0);this.setRadii(e,g)}else{this.parent.init.call(this,e,g);this.setRadii(h,h)}else{this.parent.init.call(this,e,g);this.setRadii(h,i)}};toxi.Ellipse.prototype=new toxi.Vec2D;
+toxi.Ellipse.prototype.constructor=toxi.Ellipse;toxi.Ellipse.prototype.parent=toxi.Vec2D.prototype;toxi.Ellipse.prototype.containsPoint=function(e){var g=this.getFoci();return e.distanceTo(g[0])+e.distanceTo(g[1])<2*MathUtils.max(this.radius.x,this.radius.y)};toxi.Ellipse.prototype.getArea=function(){return MathUtils.PI*radius.x*radius.y};toxi.Ellipse.prototype.getCircumference=function(){return Math.sqrt(0.5*this.radius.magSquared())*MathUtils.TWO_PI};
+toxi.Ellipse.prototype.getFoci=function(){var e=[];if(this.radius.x>this.radius.y){e[0]=this.sub(this.focus,0);e[1]=this.add(this.focus,0)}else{e[0]=this.sub(0,this.focus);e[1]=this.add(0,this.focus)}return e};toxi.Ellipse.prototype.getRadii=function(){return this.radius.copy()};toxi.Ellipse.prototype.setRadii=function(e,g){if(e instanceof toxi.Vec2D){g=e.y;e=e.x}this.radius.set(e,g);this.focus=this.radius.magnitude();return this};
+toxi.Ellipse.prototype.toPolygon2D=function(e){for(var g=new toxi.Polygon2D,h=MathUtils.TWO_PI/e,i=0;i<e;i++)g.add(toxi.Vec2D.fromTheta(i*h).scaleSelf(this.radius).addSelf(this));return g};
toxi.Rect=function(e,g,h,i){if(arguments.length===2)if(e instanceof toxi.Vec2D){this.x=e.x;this.y=e.y;this.width=g.x-this.x;this.height=g.y-this.y}else throw Error("toxi.Rect received incorrect parameters");else if(arguments.length===4){this.x=e;this.y=g;this.width=h;this.height=i}else if(arguments.length>0)throw Error("toxi.Rect received incorrect parameters");};toxi.Rect.fromCenterExtent=function(e,g){return new toxi.Rect(e.sub(g),e.add(g))};
toxi.Rect.prototype={containsPoint:function(e){var g=e.x;e=e.y;if(g<this.x||g>=this.x+this.width)return false;if(e<this.y||e>=this.y+this.height)return false;return true},copy:function(){return new toxi.Rect(this.x,this.y,this.width,this.height)},getArea:function(){return this.width*this.height},getAspect:function(){return this.width/this.height},getBottom:function(){return this.y+this.height},getBottomRight:function(){return new toxi.Vec2D(this.x+this.width,this.y+this.height)},getCentroid:function(){return new toxi.Vec2D(this.x+
this.width*0.5,this.y+this.height*0.5)},getDimensions:function(){return new toxi.Vec2D(this.width,this.height)},getEdge:function(e){var g=undefined;switch(e){case 0:g=new toxi.Line2D(new toxi.Vec2D(this.x,this.y),new toxi.Vec2D(this.x+this.width,this.y));break;case 1:g=new toxi.Line2D(new toxi.Vec2D(this.x+this.width,this.y),new toxi.Vec2D(this.x+this.width,this.y+this.height));break;case 2:g=new toxi.Line2D(new toxi.Vec2D(this.x,this.y+this.height),new toxi.Vec2D(this.x+this.width,this.y+this.height));
break;case 3:g=new toxi.Line2D(new toxi.Vec2D(this.x,this.y),new toxi.Vec2D(this.x,this.y+this.height));break;default:throw Error("edge ID needs to be 0...3");}return g},getLeft:function(){return this.x},getRight:function(){return this.x+this.width},getTop:function(){return this.y},getTopLeft:function(){return new toxi.Vec2D(this.x,this.y)},intersectsRay:function(e,g,h){var i=e.getDirection().reciprocal(),j=i.x<0,k=i.y<0,n=this.getTopLeft(),m=this.getBottomRight(),o=j?m:n,r=(o.x-e.x)*i.x;o=j?n:m;
j=(o.x-e.x)*i.x;o=k?n:m;var t=(o.y-e.y)*i.y;o=k?n:m;i=(o.y-e.y)*i.y;if(!(r>i||t>j)){if(t>r)r=t;if(i<j)j=i;if(r<h&&j>g)return e.getPointAtDistance(r)}},intersectsRect:function(e){return!(this.x>e.x+e.width||this.x+this.width<e.x||this.y>e.y+e.height||this.y+this.height<e.y)},scale:function(e){var g=this.getCentroid();this.width*=e;this.height*=e;this.x=g.x-this.width*0.5;this.y=g.y-this.height*0.5;return this},set:function(e,g,h,i){if(arguments.length==-1){this.y=e.y;this.width=e.width;this.height=
e.height;this.x=e.x}else if(arguments.length===4){this.x=e;this.y=g;this.width=h;this.height=i}else throw Error("toxi.Rect set() received wrong parameters");},setDimenions:function(e){this.width=e.x;this.height=e.y;return this},setPosition:function(e){this.x=e.x;this.y=e.y;return this},toPolygon2D:function(){var e=new toxi.Polygon2D;e.add(new toxi.Vec2D(this.x,this.y));e.add(new toxi.Vec2D(this.x+this.width,this.y));e.add(new toxi.Vec2D(this.x+this.width,this.y+this.height));e.add(new toxi.Vec2D(this.x,
-this.y+this.height));return e},toString:function(){return"rect: {x: "+this.x+", y: "+this.y+", width: "+this.width+", height: "+this.height+"}"},union:function(e){var g=MathUtils.max(this.x+this.width,e.x+e.width);this.x=MathUtils.min(this.x,e.x);this.width=g-this.x;g=MathUtils.max(this.y+this.height,e.y+e.height);this.y=MathUtils.min(this.y,e.y);this.height=g-this.y;return this}};toxi.Circle=function(e,g,h){this.circleInit(e,g,h)};toxi.Circle.prototype=new toxi.Ellipse;
-toxi.Circle.prototype.constructor=toxi.Circle;toxi.Circle.prototype.parent=toxi.Ellipse.prototype;toxi.Circle.from2Points=function(e,g){var h=e.interpolateTo(g,0.5),i=h.distanceTo(e);return new toxi.Circle(h,i)};
+this.y+this.height));return e},toString:function(){return"rect: {x: "+this.x+", y: "+this.y+", width: "+this.width+", height: "+this.height+"}"},union:function(e){var g=MathUtils.max(this.x+this.width,e.x+e.width);this.x=MathUtils.min(this.x,e.x);this.width=g-this.x;g=MathUtils.max(this.y+this.height,e.y+e.height);this.y=MathUtils.min(this.y,e.y);this.height=g-this.y;return this}};
+toxi.Circle=function(e,g,h){if(arguments.length==1)e instanceof toxi.Circle?toxi.Ellipse.apply(this,[e,e.radius.x]):toxi.Ellipse.apply(this,[0,0,e]);else arguments.length==2?toxi.Ellipse.apply(this,[e,g]):toxi.Ellipse.apply(this,[e,g,h,h])};toxi.extend(toxi.Circle,toxi.Ellipse);toxi.Circle.from2Points=function(e,g){var h=e.interpolateTo(g,0.5),i=h.distanceTo(e);return new toxi.Circle(h,i)};
toxi.Circle.from3Points=function(e,g,h){var i=undefined,j=g.sub(e),k=h.sub(g);if(toxi.MathUtils.abs(j.x)<=1.0E-7&&toxi.MathUtils.abs(k.y)<=1.0E-7){g=(new toxi.Vec2D(g.x+h.x,e.y+g.y)).scaleSelf(0.5);e=g.distanceTo(e);i=new toxi.Circle(g,e)}else{j=j.y/j.x;k=k.y/k.x;if(toxi.MathUtils.abs(j-k)>1.0E-7&&j!=0){h=(j*k*(e.y-h.y)+k*(e.x+g.x)-j*(g.x+h.x))/(2*(k-j));g=new toxi.Vec2D(h,-(h-(e.x+g.x)/2)/j+(e.y+g.y)/2);e=g.distanceTo(e);i=new toxi.Circle(g,e)}}return i};
toxi.Circle.prototype.containsPoint=function(e){return this.distanceToSquared(e)<=this.radius.x*this.radius.x};toxi.Circle.prototype.getCircumference=function(){return toxi.MathUtils.TWO_PI*this.radius.x};toxi.Circle.prototype.getRadius=function(){return this.radius.x};toxi.Circle.prototype.getTangentPoints=function(e){var g=this.interpolateTo(e,0.5);return this.intersectsCircle(new toxi.Circle(g,g.distanceTo(e)))};
-toxi.Circle.prototype.circleInit=function(e,g,h){if(g===undefined)e instanceof toxi.Circle?this.parent.ellipseInit.call(this,e,e.radius.x):this.parent.ellipseInit.call(this,0,0,e);else h===undefined?this.parent.ellipseInit.call(this,e,g):this.parent.ellipseInit.call(this,e,g,h,h);return this};
toxi.Circle.prototype.intersectsCircle=function(e){var g=null,h=e.sub(this),i=h.magnitude(),j=this.radius.x;e=e.radius.x;if(i<=j+e&&i>=Math.abs(j-e)){e=(j*j-e*e+i*i)/(2*i);i=1/i;g=this.add(h.scale(e*i));j=Math.sqrt(j*j-e*e);h.perpendicular().scaleSelf(j*i);i=g.add(h);h=g.sub(h);g=[i,h]}return g};toxi.Circle.prototype.setRadius=function(e){this.setRadii(e,e);return this};toxi.CircleIntersector=function(e){this.circle=e;this.isec=undefined};
toxi.CircleIntersector.prototype={getIntersectionData:function(){return this.isec},intersectsRay:function(e){this.isec.clear();var g=circle.sub(e),h=g.magSquared();g=g.dot(e.getDirection());var i=circle.getRadius();h=i*i-(h-g*g);if(h>=0){this.isec.isIntersection=true;this.isec.dist=g-Math.sqrt(h);this.isec.pos=e.getPointAtDistance(isec.dist);this.isec.normal=this.isec.pos.sub(this.circle).normalize()}return this.isec.isIntersection}};toxi.Line2D=function(e,g){this.a=e;this.b=g};
toxi.Line2D.prototype={closestPointTo:function(e){var g=this.b.sub(this.a);e=e.sub(this.a).dot(g)/g.magSquared();if(e<0)return this.a.copy();else if(e>1)return this.b.copy();return this.a.add(g.scaleSelf(e))},copy:function(){return new toxi.Line2D(this.a.copy(),this.b.copy())},equals:function(e){if(this==e)return true;if(!(e instanceof toxi.Line2D))return false;return(this.a.equals(e.a)||this.a.equals(e.b))&&(this.b.equals(e.b)||this.b.equals(e.a))},getDirection:function(){return this.b.sub(this.a).normalize()},
@@ -205,9 +205,7 @@ toxi.Line3D.splitIntoSegments=function(e,g,h,i,j){if(i==null)i=[];j&&i.push(e.co
toxi.Line3D.LineIntersection.prototype={getCoefficient:function(){return this.coeff},getLength:function(){if(this.line==null)return null;return this.line.getLength()},getLine:function(){if(this.line==null)return null;return this.line.copy()},getType:function(){return this.type},isIntersectionInside:function(){return this.type==toxi.Line3D.LineIntersection.Type.INTERSECTING&&this.coeff[0]>=0&&this.coeff[0]<=1&&this.coeff[1]>=0&&this.coeff[1]<=1},toString:function(){return"type: "+this.type+" line: "+
this.line}};toxi.Line3D.LineIntersection.Type={};toxi.Line3D.LineIntersection.Type.NON_INTERSECTING=0;toxi.Line3D.LineIntersection.Type.INTERSECTING=1;toxi.Ray2D=function(e,g,h){if(typeof e=="Number"){e=new toxi.Vec2D(e,g);g=h.getNormalized()}else if(e instanceof toxi.Vec2D){e=e;g=g.getNormalized()}else{e=new toxi.Vec2D;g=toxi.Vec2D.Y_AXIS.copy()}this.parent.init.call(this,e);this.dir=g};toxi.Ray2D.prototype=new toxi.Vec2D;toxi.Ray2D.constructor=toxi.Ray2D;toxi.Ray2D.prototype.parent=toxi.Vec2D.prototype;
toxi.Ray2D.prototype.getDirection=function(){return this.dir.copy()};toxi.Ray2D.prototype.getDistanceToPoint=function(e){e=e.sub(this);return e.distanceTo(this.dir.scale(e.dot(this.dir)))};toxi.Ray2D.prototype.getPointAtDistance=function(e){return this.add(this.dir.scale(e))};toxi.Ray2D.prototype.setDirection=function(e){this.dir.set(e).normalize();return this};toxi.Ray2D.prototype.toLine2DWithPointAtDistance=function(e){return new toxi.Line2D(this.copy(),this.getPointAtDistance(e))};
-toxi.Ray2D.prototype.toString=function(){return"origin: "+this.parent.toString.call(this)+" dir: "+this.dir};toxi.IsectData2D=function(e){if(e!==undefined){this.isIntersection=e.isIntersection;this.dist=e.dist;this.pos=e.pos.copy();this.dir=e.dir.copy();this.normal=e.normal.copy()}else this.clear()};
-toxi.IsectData2D.prototype={clear:function(){this.isIntersection=false;this.dist=0;this.pos=new toxi.Vec2D;this.dir=new toxi.Vec2D;this.normal=new toxi.Vec2D},toString:function(){var e="isec: "+this.isIntersection;if(this.isIntersection)e+=" at:"+this.pos+" dist:"+this.dist+" normal:"+this.normal;return e}};toxi.color=toxi.color===undefined?{}:toxi.color;
-toxi.color.TColor=function(e){this.rgb=Array(3);this.hsv=Array(3);this.cmyk=Array(4);this._alpha=1;if(e!==undefined){this.cmyk=e.toCMYKAArray().splice(0,4);this.hsv=e.toHSVAArray().splice(0,3);this.rgb=e.toRGBAArray().splice(0,3);this._alpha=e._alpha}};
+toxi.Ray2D.prototype.toString=function(){return"origin: "+this.parent.toString.call(this)+" dir: "+this.dir};toxi.color=toxi.color===undefined?{}:toxi.color;toxi.color.TColor=function(e){this.rgb=Array(3);this.hsv=Array(3);this.cmyk=Array(4);this._alpha=1;if(e!==undefined){this.cmyk=e.toCMYKAArray().splice(0,4);this.hsv=e.toHSVAArray().splice(0,3);this.rgb=e.toRGBAArray().splice(0,3);this._alpha=e._alpha}};
toxi.color.TColor.prototype={add:function(e){return this.copy().addSelf(e)},addSelf:function(e){this.rgb[0]=toxi.MathUtils.min(this.rgb[0]+e.rgb[0],1);this.rgb[1]=toxi.MathUtils.min(this.rgb[1]+e.rgb[1],1);this.rgb[2]=toxi.MathUtils.min(this.rgb[2]+e.rgb[2],1);return this.setRGB(rgb)},adjustConstrast:function(e){return this.hsv[2]<0.5?this.darken(e):this.lighten(e)},adjustHSV:function(e,g,h){return this.setHSV([this.hsv[0]+e,this.hsv[1]+g,this.hsv[2]+h])},adjustRGB:function(e,g,h){return this.setRGB([this.rgb[0]+
e,this.rgb[1]+g,this.rgb[2]+h])},alpha:function(){return this._alpha},analog:function(e,g){this.rotateRYB(toxi.MathUtils.degrees(e)*toxi.MathUtils.normalizedRandom());this.hsv[1]+=g*toxi.MathUtils.normalizedRandom();this.hsv[2]+=g*toxi.MathUtils.normalizedRandom();return this.setHSV(this.hsv)},black:function(){return this.cmyk[3]},blend:function(e,g){if(g===undefined)g=0.5;var h=e.toRGBAArray();this.rgb[0]+=(h[0]-this.rgb[0])*g;this.rgb[1]+=(h[1]-this.rgb[1])*g;this.rgb[2]+=(h[2]-this.rgb[2])*g;this._alpha+=
(e.alpha-this._alpha)*g;return this.setRGB(this.rgb)},blue:function(){return this.rgb[2]},brightness:function(){return this.hsv[2]},complement:function(){return this.rotateRYB(180)},copy:function(){return new toxi.color.TColor(this)},cyan:function(){return this.cmyk[0]},darken:function(e){this.hsv[2]=toxi.MathUtils.clip(this.hsv[2]-e,0,1);return this.setHSV(this.hsv)},desaturate:function(e){this.hsv[1]=toxi.MathUtils.clip(this.hsv[1]-e,0,1);return this.setHSV(this.hsv)},differenceTo:function(e){return toxi.color.TColor.newRGB(Math.abs(this.rgb[0]-
@@ -248,15 +246,16 @@ toxi.physics2d.AttractionBehavior.prototype={applyBehavior:function(e){var g=thi
e},setJitter:function(e){this.jitter=e},setRadius:function(e){this.radius=e;this.radiusSquared=e*e},setStrength:function(e){this.strength=e;this.attrStrength=e*this.timeStep}};toxi.physics2d.ConstantForceBehavior=function(e){this.initConstantForceBehavior(e)};
toxi.physics2d.ConstantForceBehavior.prototype={applyBehavior:function(e){e.addForce(this.scaledForce)},configure:function(e){this.timeStep=e;this.setForce(this.force)},getForce:function(){return this.force},initConstantForceBehavior:function(e){this.force=e;this.scaleForce=new toxi.Vec2D;this.timeStep=0},setForce:function(e){this.force=e;this.scaledForce=this.force.scale(this.timeStep)},toString:function(){return"behavior force: "+this.force+" scaledForce: "+this.scaledForce+" timeStep: "+this.timeStep}};
toxi.physics2d.GravityBehavior=function(e){this.initConstantForceBehavior(e)};toxi.physics2d.GravityBehavior.prototype=new toxi.physics2d.ConstantForceBehavior;toxi.physics2d.GravityBehavior.prototype.constructor=toxi.physics2d.GravityBehavior;toxi.physics2d.GravityBehavior.prototype.parent=toxi.physics2d.ConstantForceBehavior.prototype;toxi.physics2d.GravityBehavior.prototype.configure=function(e){this.timeStep=e;this.scaledForce=this.force.scale(e*e)};
-toxi.physics2d.AngularConstraint=function(e,g){if(arguments.length>1){this.theta=g;this.rootPos=new toxi.Vec2D(e)}else{this.rootPos=new toxi.Vec2D;this.theta=e}if(parseInt(this.theta)!=this.theta)this.theta=MathUtils.radians(this.theta)};toxi.physics2d.AngularConstraint.prototype.apply=function(e){var g=e.sub(this.rootPos),h=MathUtils.floor(g.heading()/this.theta)*this.theta;e.set(this.rootPos.add(toxi.Vec2D.fromTheta(h).scaleSelf(g.magnitude())))};
-toxi.physics2d.AxisConstraint=function(e,g){this.axis=e;this.constraint=g};toxi.physics2d.AxisConstraint.prototype.apply=function(e){e.setComponent(this.axis,this.constraint)};toxi.physics2d.CircularConstraint=function(e,g){this.circle=arguments.length==1?e:new toxi.Circle(e,g)};toxi.physics2d.CircularConstraint.prototype.apply=function(e){this.circle.containsPoint(e)&&e.set(this.circle.add(e.sub(this.circle).nomalizeTo(this.circle.getRadius())))};
-toxi.physics2d.MaxConstraint=function(e,g){this.axis=e;this.threshold=g};toxi.physics2d.MaxConstraint.prototype.apply=function(e){e.getComponent(this.axis)>this.threshold&&e.setComponent(this.axis,this.threshold)};toxi.physics2d.MinConstraint=function(e){this.axis=e;this.threshold=threhold};toxi.physics2d.MinConstraint.prototype.apply=function(e){e.getComponent(this.axis)<this.threshold&&e.setComponent(this.axis,this.threshold)};
-toxi.physics2d.RectConstraint=function(e,g){if(arguments.length==1)this.rect=e.copy();else if(arguments.lengt>1)this.rect=new toxi.Rect(e,g);this.intersectRay=new toxi.Ray2D(this.rect.getCentroid(),new toxi.Vec2D)};toxi.physics2d.RectConstraint.prototype={apply:function(e){this.rect.containsPoint(e)&&e.set(this.rect.intersectsRay(this.intersectRay.setDirection(this.intersectRay.sub(e)),0,Number.MAX_VALUE))},getBox:function(){return this.rect.copy()},setBox:function(e){this.rect=e.copy();this.intersectRay.set(this.rect.getCentroid())}};
-toxi.physics2d.ParticlePath2D=function(e){toxi.Spline2D.call(this,e);this.particles=[]};toxi.extend(toxi.physics2d.ParticlePath2D,toxi.Spline2D);(function(){toxi.physics2d.ParticlePath2D.prototype.createParticles=function(e,g,h,i){this.particles=[];this.computeVertices(g);g=0;h=this.getDecimatedVertices(h,true);for(g=0;g<h;g++){var j=this.createSingleParticle(v,i);this.particles.push(j);e.addParticle(j)}return this.particles}})();
-toxi.physics2d.ParticleString2D=function(e,g,h,i,j,k){this.physics=e;this.links=[];var n=undefined,m=undefined,o=undefined,r=0;if(arguments.length===3){k=h;this.particles=g||[];for(r=0;r<this.particles.length;r++){m=this.particles[r];this.physics.addParticle(m);if(n!==undefined){o=this.createSpring(n,m,n.distanceTo(m),stregnth_step);this.links.push(o);this.physics.addSpring(o)}n=m}}else{var t=g.copy(),A=h.magnitude();this.particles=[];for(r=0;r<i;r++){m=new toxi.physics2d.VerletParticle2D(t.copy(),
-j);this.particles.push(m);this.physics.particles.push(m);if(n!==undefined){o=this.createSpring(n,m,A,k);this.links.push(o);this.physics.addSpring(o)}n=m;t.addSelf(h)}}};
+toxi.physics2d.AngularConstraint=function(e,g){if(arguments.length>1){this.theta=g;this.rootPos=new toxi.Vec2D(e)}else{this.rootPos=new toxi.Vec2D;this.theta=e}if(parseInt(this.theta)!=this.theta)this.theta=toxi.MathUtils.radians(this.theta)};toxi.physics2d.AngularConstraint.prototype.applyConstraint=function(e){var g=e.sub(this.rootPos),h=toxi.MathUtils.floor(g.heading()/this.theta)*this.theta;e.set(this.rootPos.add(toxi.Vec2D.fromTheta(h).scaleSelf(g.magnitude())))};
+toxi.physics2d.AxisConstraint=function(e,g){this.axis=e;this.constraint=g};toxi.physics2d.AxisConstraint.prototype.applyConstraint=function(e){e.setComponent(this.axis,this.constraint)};toxi.physics2d.CircularConstraint=function(e,g){if(arguments.length==1)this.circle=e;else{console.log("a: "+e);this.circle=new toxi.Circle(e,g)}};toxi.physics2d.CircularConstraint.prototype.applyConstraint=function(e){this.circle.containsPoint(e)&&e.set(this.circle.add(e.sub(this.circle).normalizeTo(this.circle.getRadius())))};
+toxi.physics2d.MaxConstraint=function(e,g){this.axis=e;this.threshold=g};toxi.physics2d.MaxConstraint.prototype.applyConstraint=function(e){e.getComponent(this.axis)>this.threshold&&e.setComponent(this.axis,this.threshold)};toxi.physics2d.MinConstraint=function(e,g){this.axis=e;this.threshold=g};toxi.physics2d.MinConstraint.prototype.applyConstraint=function(e){e.getComponent(this.axis)<this.threshold&&e.setComponent(this.axis,this.threshold)};
+toxi.physics2d.RectConstraint=function(e,g){if(arguments.length==1)this.rect=e.copy();else if(arguments.length>1)this.rect=new toxi.Rect(e,g);this.intersectRay=new toxi.Ray2D(this.rect.getCentroid(),new toxi.Vec2D)};
+toxi.physics2d.RectConstraint.prototype={applyConstraint:function(e){this.rect.containsPoint(e)&&e.set(this.rect.intersectsRay(this.intersectRay.setDirection(this.intersectRay.sub(e)),0,Number.MAX_VALUE))},getBox:function(){return this.rect.copy()},setBox:function(e){this.rect=e.copy();this.intersectRay.set(this.rect.getCentroid())}};toxi.physics2d.ParticlePath2D=function(e){toxi.Spline2D.call(this,e);this.particles=[]};toxi.extend(toxi.physics2d.ParticlePath2D,toxi.Spline2D);
+(function(){toxi.physics2d.ParticlePath2D.prototype.createParticles=function(e,g,h,i){this.particles=[];this.computeVertices(g);g=0;h=this.getDecimatedVertices(h,true);for(g=0;g<h;g++){var j=this.createSingleParticle(v,i);this.particles.push(j);e.addParticle(j)}return this.particles}})();
+toxi.physics2d.ParticleString2D=function(e,g,h,i,j,k){this.physics=e;this.links=[];var n=undefined,m=undefined,o=undefined,r=0;if(arguments.length===3){k=h;this.particles=g||[];for(r=0;r<this.particles.length;r++){m=this.particles[r];this.physics.addParticle(m);if(n!==undefined){o=this.createSpring(n,m,n.distanceTo(m),h);this.links.push(o);this.physics.addSpring(o)}n=m}}else{var t=g.copy(),A=h.magnitude();this.particles=[];for(r=0;r<i;r++){m=new toxi.physics2d.VerletParticle2D(t.copy(),j);this.particles.push(m);
+this.physics.particles.push(m);if(n!==undefined){o=this.createSpring(n,m,A,k);this.links.push(o);this.physics.addSpring(o)}n=m;t.addSelf(h)}}};
toxi.physics2d.ParticleString2D.prototype={clear:function(){for(var e=0,g=this.links.length;e<g;e++)this.physics.removeSpringElements(s);this.particles.clear();this.links.clear()},createSpring:function(e,g,h,i){return new toxi.physics2d.VerletSpring2D(e,g,h,i)},getHead:function(){return this.particles[0]},getNumParticles:function(){return this.particles.length},getTail:function(){return this.particles[this.particles.length-1]}};
-toxi.physics2d.PullBackString2D=function(e,g,h){toxi.physics2d.VerletSpring2D.call(this,e,g,h);e.lock();this.setRestLength(0.5)};toxi.extend(toxi.physics2d.PullBackString2D,toxi.physics2d.VerletSpring2D);toxi.physics2d.PullBackString2D.prototype.update=function(e){this.b.distanceToSquared(this.a)>this.restLengthSquared&&this.parent.update.call(this,e)};
+toxi.physics2d.PullBackString2D=function(e,g,h){toxi.physics2d.VerletSpring2D.call(this,e,g,0,h);e.lock();this.setRestLength(0.5)};toxi.extend(toxi.physics2d.PullBackString2D,toxi.physics2d.VerletSpring2D);toxi.physics2d.PullBackString2D.prototype.update=function(e){this.b.distanceToSquared(this.a)>this.restLengthSquared&&this.parent.update.call(this,e)};
toxi.physics2d.VerletConstrainedSpring2D=function(e,g,h,i,j){toxi.physics2d.VerletSpring2D.call(this,e,g,h,i);this.limit=j===undefined?Number.MAX_VALUE:j};toxi.extend(toxi.physics2d.VerletConstrainedSpring2D,toxi.physics2d.VerletSpring2D);
toxi.physics2d.VerletConstrainedSpring2D.update=function(e){var g=this.b.sub(this.a),h=g.magnitude()+toxi.physics2d.VerletSpring2D.EPS;h=(h-this.restLength)/(h*(this.a.invWeight+this.b.invWeight))*this.strength;if(!this.a.isLocked&&!this.isALocked){this.a.addSelf(g.scale(h*this.a.invWeight).limit(this.limit));e&&this.a.applyConstraints()}if(!this.b.isLocked&&!this.isBLocked){this.b.subSelf(g.scale(h*this.b.invWeight).limit(this.limit));e&&this.b.applyConstraints()}};
toxi.physics2d.VerletMinDistanceSpring2D=function(e,g,h,i){toxi.physics2d.VerletSpring2D.call(this,e,g,h,i);this.setRestLength(h)};toxi.extend(toxi.physics2d.VerletMinDistanceSpring2D,toxi.physics2d.VerletSpring2D);toxi.physics2d.VerletMinDistanceSpring2D.prototype.update=function(e){this.b.distanceToSquared(this.a)<this.restLengthSquared&&this.parent.update.call(this,e)};
View
184 examples/Attraction2D_pjs.html
@@ -0,0 +1,184 @@
+<!doctype html>
+
+<html lang="en">
+<head>
+ <title>Attraction 2D - toxiclibs.js examples</title>
+ <meta name="author" content="Kyle Phillips">
+ <!-- Date: 2011-01-09 -->
+ <script type="text/javascript" src="../build/toxiclibs.js"></script>
+
+ <script type="text/javascript" src="js/processing.js"></script>
+ <link href="css/style.css" rel="stylesheet" type="text/css" media="screen">
+ <script>
+ /*
+ * This code searches for all the <script type="application/processing" target="canvasid">
+ * in your page and loads each script in the target canvas with the proper id.
+ * It is useful to smooth the process of adding Processing code in your page and starting
+ * the Processing.js engine.
+ */
+
+ if (window.addEventListener) {
+ window.addEventListener("load", function() {
+ var scripts = document.getElementsByTagName("script");
+ var canvasArray = Array.prototype.slice.call(document.getElementsByTagName("canvas"));
+ var canvas;
+ for (var i = 0, j = 0; i < scripts.length; i++) {
+ if (scripts[i].type == "application/processing") {
+ var src = scripts[i].getAttribute("target");
+ if (src && src.indexOf("#") > -1) {
+ canvas = document.getElementById(src.substr(src.indexOf("#") + 1));
+ if (canvas) {
+ new Processing(canvas, scripts[i].text);
+ for (var k = 0; k< canvasArray.length; k++)
+ {
+ if (canvasArray[k] === canvas) {
+ // remove the canvas from the array so we dont override it in the else
+ canvasArray.splice(k,1);
+ }
+ }
+ }
+ } else {
+ if (canvasArray.length >= j) {
+ new Processing(canvasArray[j], scripts[i].text);
+ }
+ j++;
+ }
+ }
+ }
+ }, false);
+ }
+
+ </script>
+</head>
+<body class="container_12">
+ <header class="grid_12">
+ <hgroup>
+ <h1>Attraction 2D</h1><h2>w/ <a href="http://processingjs.org">Processing.js</a>
+ </hgroup>
+ </header>
+<script type="application/processing">
+
+/**
+ * <p>This example demonstrates how to use the behavior handling
+ * (new since toxiclibs-0020 release) and specifically the attraction
+ * behavior to create forces around the current locations of particles
+ * in order to attract (or deflect) other particles nearby.</p>
+ *
+ * <p>Behaviors can be added and removed dynamically on both a
+ * global level (for the entire physics simulation) as well as for
+ * individual particles only.</p>
+ *
+ * <p>Usage: Click and drag mouse to attract particles</p>
+ */
+
+/*
+ * Copyright (c) 2010 Karsten Schmidt
+ *
+ * This demo & library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * http://creativecommons.org/licenses/LGPL/2.1/
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+import toxi.geom.*;
+import toxi.physics2d.*;
+import toxi.physics2d.behaviors.*;
+
+int NUM_PARTICLES = 250;
+
+VerletPhysics2D physics;
+AttractionBehavior mouseAttractor;
+
+Vec2D mousePos;
+
+void setup() {
+ size(680, 382);
+ // setup physics with 10% drag
+ physics = new toxi.physics2d.VerletPhysics2D();
+ physics.setDrag(0.05);
+ physics.setWorldBounds(new toxi.Rect(0, 0, width, height));
+ // the NEW way to add gravity to the simulation, using behaviors
+ physics.addBehavior(new toxi.physics2d.GravityBehavior(new toxi.Vec2D(0, 0.15)));
+}
+
+void addParticle() {
+ Vec2D randLoc = toxi.Vec2D.randomVector().scale(5).addSelf(width / 2, 0);
+ VerletParticle2D p = new toxi.physics2d.VerletParticle2D(randLoc);
+ physics.addParticle(p);
+ // add a negative attraction force field around the new particle
+ physics.addBehavior(new toxi.physics2d.AttractionBehavior(p, 20, -1.2, 0.01));
+}
+
+void draw() {
+ background(255,0,0);
+ noStroke();
+ fill(255);
+ if (physics.particles.length < NUM_PARTICLES) {
+ addParticle();
+ }
+ physics.update();
+ for (int i=0;i<physics.particles.length;i++) {
+ VerletParticle2D p = physics.particles[i];
+ ellipse(p.x, p.y, 5, 5);
+ }
+
+
+}
+
+void mousePressed() {
+ addParticle();
+ mousePos = new toxi.Vec2D(mouseX, mouseY);
+ // create a new positive attraction force field around the mouse position (radius=250px)
+ mouseAttractor = new toxi.physics2d.AttractionBehavior(mousePos, 250, 0.9);
+ physics.addBehavior(mouseAttractor);
+}
+
+void mouseDragged() {
+ // update mouse attraction focal point
+ mousePos.set(mouseX, mouseY);
+}
+
+void mouseReleased() {
+ // remove the mouse attraction when button has been released
+ physics.removeBehavior(mouseAttractor);
+}
+
+
+</script>
+
+<canvas id="myCanvas" width="200" height="200">
+ your browser doesnt support canvas
+</canvas>
+<section class="grid_12" id="details">
+<aside id="authors" class="grid_6">
+<p>original example by <a href="http://postspectacular.com">Karsten Schmidt</a><br/>
+ Toxiclibs ported to js by <a href="http://workofkylephillips.com">Kyle Phillips</a></p>
+</aside>
+<aside id="usage" class="grid_6">
+ <p><strong>Usage:</strong><br><ul>
+ <li>Click and drag mouse to attract particles</li>
+ </ul></p>
+</aside>
+<article id="description" class="grid_12">
+<p>This example demonstrates how to use the behavior handling
+(new since toxiclibs-0020 release) and specifically the attraction
+behavior to create forces around the current locations of particles
+in order to attract (or deflect) other particles nearby.</p>
+<p>Behaviors can be added and removed dynamically on both a
+global level (for the entire physics simulation) as well as for
+individual particles only.</p>
+ </article>
+</section>
+</body>
+</html>
View
52 src/core/geom/Circle.js
@@ -5,13 +5,29 @@
*/
toxi.Circle = function(a,b,c) {
- this.circleInit(a,b,c);
-}
+ if(arguments.length == 1)
+ {
+ if(a instanceof toxi.Circle)
+ {
+ toxi.Ellipse.apply(this,[a,a.radius.x]);
+ }
+ else
+ {
+ toxi.Ellipse.apply(this,[0,0,a]);
+ }
+ }
+ else if(arguments.length == 2)
+ {
+ toxi.Ellipse.apply(this,[a,b]);
+ }
+ else
+ {
+ toxi.Ellipse.apply(this,[a,b,c,c]);
+ }
+};
-toxi.Circle.prototype = new toxi.Ellipse();
-toxi.Circle.prototype.constructor = toxi.Circle;
-toxi.Circle.prototype.parent = toxi.Ellipse.prototype;
+toxi.extend(toxi.Circle,toxi.Ellipse);
@@ -87,32 +103,6 @@ toxi.Circle.prototype.getTangentPoints = function(p) {
return this.intersectsCircle(new toxi.Circle(m, m.distanceTo(p)));
}
-toxi.Circle.prototype.circleInit = function(a,b,c){
- if(b === undefined)
- {
- if(a instanceof toxi.Circle)
- {
- this.parent.ellipseInit.call(this,a,a.radius.x);
- }
- else
- {
- this.parent.ellipseInit.call(this,0,0,a);
- }
- }
- else
- {
- if(c === undefined)
- {
- this.parent.ellipseInit.call(this,a,b);
- }
- else
- {
- this.parent.ellipseInit.call(this,a,b,c,c);
- }
-
- }
- return this;
-}
toxi.Circle.prototype.intersectsCircle = function(c) {
var res = null;
View
83 src/core/geom/Ellipse.js
@@ -3,7 +3,44 @@
*/
toxi.Ellipse = function(a,b,c,d) {
- this.ellipseInit(a,b,c,d);
+ this.radius = new toxi.Vec2D();
+ if(arguments.length == 0){
+ this.parent.init.call(this,0,0);
+ this.setRadii(1,1);
+ }
+ else if(a instanceof toxi.Vec2D)
+ {
+ this.parent.init.call(this,a.x,a.y);
+ if(b instanceof toxi.Vec2D)
+ {
+ this.setRadii(b.x,b.y);
+ }
+ else
+ {
+ this.setRadii(b,b);
+ }
+ }
+ else
+ {
+ if(d === undefined)
+ {
+ if(c === undefined)
+ {
+ this.parent.init.call(this,0,0);
+ this.setRadii(a,b);
+ }
+ else
+ {
+ this.parent.init.call(this,a,b);
+ this.setRadii(c,c);
+ }
+ }
+ else
+ {
+ this.parent.init.call(this,a,b);
+ this.setRadii(c,d);
+ }
+ }
}
@@ -66,50 +103,6 @@ toxi.Ellipse.prototype.getRadii = function() {
}
-toxi.Ellipse.prototype.ellipseInit = function(a,b,c,d){
- this.radius = new toxi.Vec2D();
- if(a === undefined){
- this.parent.init.call(this,0,0);
- this.setRadii(1,1);
- }
- else if(a instanceof toxi.Vec2D)
- {
- this.parent.init.call(this,a.x,a.y);
- if(b instanceof toxi.Vec2D)
- {
- this.setRadii(b.x,b.y);
- }
- else
- {
- this.setRadii(b,b);
- }
- }
- else
- {
- if(d === undefined)
- {
- if(c === undefined)
- {
- this.parent.init.call(this,0,0);
- this.setRadii(a,b);
- }
- else
- {
- this.parent.init.call(this,a,b);
- this.setRadii(c,c);
- }
- }
- else
- {
- this.parent.init.call(this,a,b);
- this.setRadii(c,d);
- }
- }
- return this;
-}
-
-
-
/**
* Sets the radii of the ellipse to the new values.
*
View
55 src/core/geom/Vec2D.js
@@ -12,7 +12,18 @@ toxi.Vec2D = function(a,b){
this.init(a,b);
}
-
+
+toxi.Vec2D.Axis = {
+ X: {
+ getVector: function(){ return toxi.Vec2D.X_AXIS; },
+ toString: function(){ return "toxi.Vec2D.Axis.X"; }
+ },
+ Y: {
+ getVector: function(){ return toxi.Vec2D.Y_AXIS; },
+ toString: function(){ return "toxi.Vec2D.Axis.Y"; }
+ }
+};
+
toxi.Vec2D.prototype = {
abs: function() {
@@ -165,22 +176,16 @@ toxi.Vec2D.prototype = {
},
getComponent: function(id) {
- if(id instanceof Number)
- {
- switch(id) {
- case 0:
- id = toxi.Vec2D.Axis.X;
- case 1:
- id = toxi.Vec2D.Axis.Y;
- }
+ if(typeof id == 'number')
+ {
+ id = (id == 0) ? toxi.Vec2D.Axis.X : toxi.Vec2D.Axis.Y;
}
- switch (id) {
- case toxi.Vec2D.Axis.X:
- return this.x;
- case toxi.Vec2D.Axis.Y:
- return this.y;
- }
- return 0;
+ if(id == toxi.Vec2D.Axis.X){
+ return this.x;
+ } else if(id == toxi.Vec2D.Axis.Y){
+ return this.y;
+ }
+ return 0;
},
getConstrained: function(r) {
@@ -510,13 +515,10 @@ toxi.Vec2D.prototype = {
},
setComponent: function(id, val) {
- switch (id) {
- case toxi.Vec2D.Axis.X:
+ if(id === toxi.Vec2D.Axis.X){
this.x = val;
- break;
- case toxi.Vec2D.Axis.Y:
+ } else if(id === toxi.Vec2D.Axis.Y){
this.y = val;
- break;
}
return this;
},
@@ -612,14 +614,3 @@ toxi.Vec2D.randomVector = function(rnd){
var v = new toxi.Vec2D(Math.random()*2 - 1, Math.random() * 2 - 1);
return v.normalize();
}
-
-
-
-toxi.Vec2D.Axis = {
- X: {
- getVector: function(){ return toxi.Vec2D.X_AXIS; }
- },
- Y: {
- getVector: function(){ return toxi.Vec2D.Y_AXIS; }
- }
-};
View
24 src/physics/physics2d/ParticleString2D.js
@@ -25,7 +25,7 @@
p = this.particles[i];
this.physics.addParticle(p);
if(prev !== undefined){
- s = this.createSpring(prev,p,prev.distanceTo(p),stregnth_step);
+ s = this.createSpring(prev,p,prev.distanceTo(p),strength_step);
this.links.push(s);
this.physics.addSpring(s);
}
@@ -53,7 +53,17 @@
}
};
- /**
+
+
+toxi.physics2d.ParticleString2D.prototype = {
+ clear: function(){
+ for(var i = 0, len = this.links.length; i < len; i++){
+ this.physics.removeSpringElements(s);
+ }
+ this.particles.clear();
+ this.links.clear();
+ },
+ /**
* Creates a number of particles along a line and connects them into a
* string using springs.
*
@@ -70,16 +80,6 @@
* @param strength
* spring strength
*/
-
-toxi.physics2d.ParticleString2D.prototype = {
- clear: function(){
- for(var i = 0, len = this.links.length; i < len; i++){
- this.physics.removeSpringElements(s);
- }
- this.particles.clear();
- this.links.clear();
- },
-
createSpring: function(a,b,len,strength){
return new toxi.physics2d.VerletSpring2D(a,b,len,strength);
},
View
2  src/physics/physics2d/PullBackString2D.js
@@ -6,7 +6,7 @@
*/
toxi.physics2d.PullBackString2D = function(a,b,strength){
- toxi.physics2d.VerletSpring2D.call(this,a,b,strength);
+ toxi.physics2d.VerletSpring2D.call(this,a,b,0,strength);
a.lock();
this.setRestLength(0.5);
};
View
7 src/physics/physics2d/constraints/AngularConstraint.js
@@ -1,3 +1,4 @@
+//either Vec2D + angle
toxi.physics2d.AngularConstraint = function(theta_p,theta){
if(arguments.length > 1){
@@ -9,13 +10,13 @@ toxi.physics2d.AngularConstraint = function(theta_p,theta){
this.theta = theta_p;
}
if(parseInt(this.theta) != this.theta){
- this.theta = MathUtils.radians(this.theta);
+ this.theta = toxi.MathUtils.radians(this.theta);
}
};
-toxi.physics2d.AngularConstraint.prototype.apply = function(p){
+toxi.physics2d.AngularConstraint.prototype.applyConstraint = function(p){
var delta = p.sub(this.rootPos);
- var heading = MathUtils.floor(delta.heading() / this.theta) * this.theta;
+ var heading = toxi.MathUtils.floor(delta.heading() / this.theta) * this.theta;
p.set(this.rootPos.add(toxi.Vec2D.fromTheta(heading).scaleSelf(delta.magnitude())));
};
View
6 src/physics/physics2d/constraints/AxisConstraint.js
@@ -1,11 +1,11 @@
/**
* Constrains a particle's movement by locking a given axis to a fixed value.
*/
-toxi.physics2d.AxisConstraint = function(axis,constraint){
+toxi.physics2d.AxisConstraint = function(axis,constraintAmount){
this.axis = axis;
- this.constraint = constraint;
+ this.constraint = constraintAmount;
};
-toxi.physics2d.AxisConstraint.prototype.apply = function(p){
+toxi.physics2d.AxisConstraint.prototype.applyConstraint = function(p){
p.setComponent(this.axis,this.constraint);
};
View
5 src/physics/physics2d/constraints/CircularConstraint.js
@@ -2,12 +2,13 @@ toxi.physics2d.CircularConstraint = function(a,b){
if(arguments.length == 1){
this.circle = a;
} else {
+ console.log("a: "+a);
this.circle = new toxi.Circle(a,b);
}
};
-toxi.physics2d.CircularConstraint.prototype.apply = function(p){
+toxi.physics2d.CircularConstraint.prototype.applyConstraint = function(p){
if(this.circle.containsPoint(p)){
- p.set(this.circle.add(p.sub(this.circle).nomalizeTo(this.circle.getRadius())));
+ p.set(this.circle.add(p.sub(this.circle).normalizeTo(this.circle.getRadius())));
}
};
View
2  src/physics/physics2d/constraints/MaxConstraint.js
@@ -3,7 +3,7 @@ toxi.physics2d.MaxConstraint = function(axis,threshold){
this.threshold = threshold;
};
-toxi.physics2d.MaxConstraint.prototype.apply = function(p){
+toxi.physics2d.MaxConstraint.prototype.applyConstraint = function(p){
if(p.getComponent(this.axis) > this.threshold){
p.setComponent(this.axis,this.threshold);
}
View
4 src/physics/physics2d/constraints/MinConstraint.js
@@ -1,9 +1,9 @@
toxi.physics2d.MinConstraint = function(axis,threshold){
this.axis = axis;
- this.threshold = threhold;
+ this.threshold = threshold;
};
-toxi.physics2d.MinConstraint.prototype.apply = function(p){
+toxi.physics2d.MinConstraint.prototype.applyConstraint = function(p){
if(p.getComponent(this.axis) < this.threshold){
p.setComponent(this.axis, this.threshold);
}
View
4 src/physics/physics2d/constraints/RectConstraint.js
@@ -1,14 +1,14 @@
toxi.physics2d.RectConstraint = function(a,b){
if(arguments.length == 1){
this.rect = a.copy();
- } else if(arguments.lengt > 1){
+ } else if(arguments.length > 1){
this.rect = new toxi.Rect(a,b);
}
this.intersectRay = new toxi.Ray2D(this.rect.getCentroid(), new toxi.Vec2D());
};
toxi.physics2d.RectConstraint.prototype = {
- apply: function(p){
+ applyConstraint: function(p){
if(this.rect.containsPoint(p)){
p.set(this.rect.intersectsRay(this.intersectRay.setDirection(this.intersectRay.sub(p)),0,Number.MAX_VALUE));
}
View
2  utils/REVISION
@@ -1 +1 @@
-33
+34
View
6 utils/build.py
@@ -52,8 +52,7 @@
'core/geom/YAxisCylinder.js',
'core/geom/ZAxisCylinder.js',
'core/geom/Line3D.js',
- 'core/geom/Ray2D.js',
- 'core/geom/IsectData2D.js',
+ 'core/geom/Ray2D.js'
]
COLOR_FILES = [
@@ -81,7 +80,6 @@
'physics/physics2d/VerletConstrainedSpring2D.js',
'physics/physics2d/VerletMinDistanceSpring2D.js',
'physics/physics2d/VerletPhysics2D.js'
-
]
@@ -207,7 +205,7 @@ def main(argv=None):
config = [
['toxiclibs','common', COMMON_FILES + COLOR_FILES + PHYSICS2D_FILES, args.common],
['toxi-core','core', COMMON_FILES, args.core],
- ['toxi-color','color', COLOR_FILES, args.cologitr],
+ ['toxi-color','color', COLOR_FILES, args.color],
['toxi-physics2d','physics2d', PHYSICS2D_FILES, args.physics2d]
]
Please sign in to comment.
Something went wrong with that request. Please try again.