Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

r40 new build, new uncompressed builds for easier debugging.

Lint free! Edits across most files, bugfixes in several. Looser instance-testing to allow normal  JS objects in some functions.
  • Loading branch information...
commit 4ed20c52d3f1ca0b1d15117fec8e7eda04b3a056 1 parent f0ab8e5
@hapticdata hapticdata authored
Showing with 21,610 additions and 3,704 deletions.
  1. +4 −0 .gitignore
  2. +20 −21 build/toxi-color.js
  3. +213 −211 build/toxi-core.js
  4. +16 −16 build/toxi-physics2d.js
  5. +264 −263 build/toxiclibs.js
  6. +941 −0 build/uncompressed/toxi-color-debug.js
  7. +7,315 −0 build/uncompressed/toxi-core-debug.js
  8. +816 −0 build/uncompressed/toxi-physics2d-debug.js
  9. +9,069 −0 build/uncompressed/toxiclibs-debug.js
  10. +0 −1  examples/MeshAlignToAxis_webgl.html
  11. +9 −43 examples/PolarLines_pjs.html
  12. +905 −928 src/color/TColor.js
  13. +1 −1  src/color/toxi-color.js
  14. +39 −59 src/core/geom/AABB.js
  15. +70 −75 src/core/geom/AxisAlignedCylinder.js
  16. +21 −21 src/core/geom/BernsteinPolynomial.js
  17. +25 −23 src/core/geom/Circle.js
  18. +1 −1  src/core/geom/CircleIntersector.js
  19. +8 −8 src/core/geom/Cone.js
  20. +4 −4 src/core/geom/Ellipse.js
  21. +1 −1  src/core/geom/IsectData2D.js
  22. +1 −1  src/core/geom/IsectData3D.js
  23. +30 −47 src/core/geom/Line2D.js
  24. +24 −34 src/core/geom/Line3D.js
  25. +499 −521 src/core/geom/Matrix4x4.js
  26. +8 −9 src/core/geom/Polygon2D.js
  27. +16 −14 src/core/geom/Quaternion.js
  28. +2 −2 src/core/geom/Ray2D.js
  29. +24 −31 src/core/geom/Ray3D.js
  30. +2 −2 src/core/geom/Rect.js
  31. +63 −51 src/core/geom/Sphere.js
  32. +9 −8 src/core/geom/Spline2D.js
  33. +10 −12 src/core/geom/Triangle.js
  34. +92 −94 src/core/geom/Triangle2D.js
  35. +30 −49 src/core/geom/Vec2D.js
  36. +4 −4 src/core/geom/Vec2D_post.js
  37. +65 −80 src/core/geom/Vec3D.js
  38. +71 −108 src/core/geom/mesh/BezierPatch.js
  39. +8 −9 src/core/geom/mesh/Face.js
  40. +1 −1  src/core/geom/mesh/Mesh3D.js
  41. +2 −2 src/core/geom/mesh/Selectors.js
  42. +1 −1  src/core/geom/mesh/SphereFunction.js
  43. +23 −23 src/core/geom/mesh/SuperEllipsoid.js
  44. +94 −71 src/core/geom/mesh/SurfaceMeshBuilder.js
  45. +594 −600 src/core/geom/mesh/TriangleMesh.js
  46. +4 −5 src/core/geom/mesh/VertexSelector.js
  47. +32 −48 src/core/math/InterpolateStrategy.js
  48. +3 −64 src/core/math/MathUtils.js
  49. +5 −6 src/core/math/ScaleMap.js
  50. +5 −6 src/core/math/SinCosLUT.js
  51. +12 −23 src/core/math/Waves.js
  52. +84 −56 src/physics/physics2d/ParticleString2D.js
  53. +12 −13 src/physics/physics2d/PullBackString2D.js
  54. +2 −2 src/physics/physics2d/VerletParticle2D.js
  55. +15 −21 src/physics/physics2d/VerletPhysics2D.js
  56. +1 −1  src/physics/physics2d/constraints/AngularConstraint.js
  57. +1 −2  src/physics/physics2d/physics2d.js
  58. +10 −1 src/toxi.js
  59. +1 −1  utils/REVISION
  60. +8 −5 utils/build.py
View
4 .gitignore
@@ -0,0 +1,4 @@
+.project
+.settings
+tests/*
+site/*
View
41 build/toxi-color.js
@@ -1,29 +1,28 @@
-// toxi-color.js r38 - http://github.com/hapticdata/toxiclibsjs
-toxi.color=toxi.color===undefined?{}:toxi.color;var dec2hex=function(a){var b="0000";if(a>=0&&a<=15)b="000"+a.toString(16);else if(a>=16&&a<=255)b="00"+a.toString(16);else if(a>=256&&a<=4095)b="0"+a.toString(16);else if(a>=4096&&a<=65535)b=a.toString(16);return b};
-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+=
-(a.alpha()-this._alpha)*b;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(a){this.hsv[2]=toxi.MathUtils.clip(this.hsv[2]-a,0,1);return this.setHSV(this.hsv)},desaturate:function(a){this.hsv[1]=toxi.MathUtils.clip(this.hsv[1]-a,0,1);return this.setHSV(this.hsv)},differenceTo:function(a){return toxi.color.TColor.newRGB(Math.abs(this.rgb[0]-
+// toxi-color r40 - http://github.com/hapticdata/toxiclibsjs
+toxi.color=toxi.color||{};
+(function(){var h=function(a){var b="0000";if(a>=0&&a<=15)b="000"+a.toString(16);else if(a>=16&&a<=255)b="00"+a.toString(16);else if(a>=256&&a<=4095)b="0"+a.toString(16);else if(a>=4096&&a<=65535)b=a.toString(16);return b};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+=(a.alpha()-
+this._alpha)*b;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(a){this.hsv[2]=toxi.MathUtils.clip(this.hsv[2]-a,0,1);return this.setHSV(this.hsv)},desaturate:function(a){this.hsv[1]=toxi.MathUtils.clip(this.hsv[1]-a,0,1);return this.setHSV(this.hsv)},differenceTo:function(a){return toxi.color.TColor.newRGB(Math.abs(this.rgb[0]-
a.rgb[0]),Math.abs(this.rgb[1]-a.rgb[1]),Math.abs(this.rgb[2]-a.rgb[2]))},distanceToCMYK:function(a){var b=a.toCMYKAArray();a=this.cmyk[0]-b[0];var d=this.cmyk[1]-b[1],c=this.cmyk[2]-b[2];b=this.cmyk[3]-b[3];return Math.sqrt(a*a+d*d+c*c+b*b)},distanceToHSV:function(a){var b=this.hsv[0]*toxi.MathUtils.TWO_PI,d=a.hue()*toxi.MathUtils.TWO_PI;b=new toxi.Vec3D(Math.cos(b)*this.hsv[1],Math.sin(b)*this.hsv[1],this.hsv[2]);a=new toxi.Vec3D(Math.cos(d)*a.saturation(),Math.sin(d)*a.saturation(),a.brightness());
return b.distanceTo(a)},distanceToRGB:function(a){var b=a.toRGBAArray();a=this.rgb[0]-b[0];var d=this.rgb[1]-b[1];b=this.rgb[2]-b[2];return Math.sqrt(a*a+d*d+b*b)},equals:function(a){if(a!==undefined&&a instanceof toxi.color.TColor){var b=a.rgb[0]-this.rgb[0],d=a.rgb[1]-this.rgb[1],c=a.rgb[2]-this.rgb[2];a=a.alpha()-this._alpha;return Math.sqrt(b*b+d*d+c*c+a*a)<toxi.color.TColor.EPS}return false},getAnalog:function(a,b){return(new toxi.color.TColor(this)).analog(a,b)},getBlended:function(a,b){return(new toxi.color.TColor(this)).blend(a,
b)},getComplement:function(){return(new toxi.color.TColor(this)).complement()},getComponentValue:function(a){return a.getComponentValueFor(this)},getDarkened:function(a){return(new toxi.color.TColor(this)).darken(a)},getDesaturated:function(a){return(new toxi.color.TColor(this)).desaturate(a)},getDifferenceTo:function(a){return this.copy().differenceTo(a)},getInverted:function(){return(new toxi.color.TColor(this)).invert()},getLightened:function(a){return(new toxi.color.TColor(this)).lighten(a)},
getRotatedRYB:function(a){return(new toxi.color.TColor(this)).rotateRYB(a)},getSaturated:function(a){return(new toxi.color.TColor(this)).saturate(a)},green:function(){return this.rgb[1]},hue:function(){return this.hsv[0]},invert:function(){this.rgb[0]=1-this.rgb[0];this.rgb[1]=1-this.rgb[1];this.rgb[2]=1-this.rgb[2];return this.setRGB(this.rgb)},isBlack:function(){return this.rgb[0]<=toxi.color.TColor.BLACK_POINT&&this.rgb[0]==this.rgb[1]&&this.rgb[0]==this.rgb[2]},isGrey:function(){return this.hsv[1]<
-toxi.color.TColor.GREY_THRESHOLD},isWhite:function(){return this.rgb[0]>=toxi.color.TColor.WHITE_POINT&&this.rgb[0]==this.rgb[1]&&this.rgb[0]==this.rgb[2]},lighten:function(a){this.hsv[2]=toxi.MathUtils.clip(this.hsv[2]+a,0,1);return this.setHSV(this.hsv)},luminance:function(){return this.rgb[0]*0.299+this.rgb[1]*0.587+this.rgb[2]*0.114},magenta:function(){return this.cmyk[1]},red:function(){return this.rgb[0]},rotateRYB:function(a){parseInt(toxi.MathUtils.degrees(a));var b=this.hsv[0]*360;a%=360;
-for(var d=0,c=0;c<toxi.color.TColor.RYB_WHEEL.length-1;c++){var e=toxi.color.TColor.RYB_WHEEL[c],f=toxi.color.TColor.RYB_WHEEL[c+1];if(f.y<e.y)f.y+=360;if(e.y<=b&&b<=f.y){d=e.x+(f.x-e.x)*(b-e.y)/(f.y-e.y);break}}d=(d+a)%360;for(c=0;c<toxi.color.TColor.RYB_WHEEL.length-1;c++){e=toxi.color.TColor.RYB_WHEEL[c];f=toxi.color.TColor.RYB_WHEEL[c+1];if(f.y<e.y)f.y+=360;if(e.x<=d&&d<=f.x){b=e.y+(f.y-e.y)*(d-e.x)/(f.x-e.x);break}}this.hsv[0]=b%360/360;return this.setHSV(this.hsv)},saturate:function(a){this.hsv[1]=
+toxi.color.TColor.GREY_THRESHOLD},isWhite:function(){return this.rgb[0]>=toxi.color.TColor.WHITE_POINT&&this.rgb[0]==this.rgb[1]&&this.rgb[0]==this.rgb[2]},lighten:function(a){this.hsv[2]=toxi.MathUtils.clip(this.hsv[2]+a,0,1);return this.setHSV(this.hsv)},luminance:function(){return this.rgb[0]*0.299+this.rgb[1]*0.587+this.rgb[2]*0.114},magenta:function(){return this.cmyk[1]},red:function(){return this.rgb[0]},rotateRYB:function(a){parseInt(toxi.MathUtils.degrees(a),10);var b=this.hsv[0]*360,d=0,
+c,e;a%=360;var f=0;for(d=0;d<toxi.color.TColor.RYB_WHEEL.length-1;d++){c=toxi.color.TColor.RYB_WHEEL[d];e=toxi.color.TColor.RYB_WHEEL[d+1];if(e.y<c.y)e.y+=360;if(c.y<=b&&b<=e.y){f=c.x+(e.x-c.x)*(b-c.y)/(e.y-c.y);break}}f=(f+a)%360;for(d=0;d<toxi.color.TColor.RYB_WHEEL.length-1;d++){c=toxi.color.TColor.RYB_WHEEL[d];e=toxi.color.TColor.RYB_WHEEL[d+1];if(e.y<c.y)e.y+=360;if(c.x<=f&&f<=e.x){b=c.y+(e.y-c.y)*(f-c.x)/(e.x-c.x);break}}this.hsv[0]=b%360/360;return this.setHSV(this.hsv)},saturate:function(a){this.hsv[1]=
toxi.MathUtils.clip(this.hsv[1]+a,0,1);return this.setHSV(this.hsv)},saturation:function(){return this.hsv[1]},setAlpha:function(a){this._alpha=a;return this},setARGB:function(a){this.setRGB((a>>16&255)*toxi.TColor.INV8BIT,(a>>8&255)*toxi.TColor.INV8BIT,(a&255)*toxi.TColor.INV8BIT);this._alpha=(a>>>24)*toxi.TColor.INV8BIT;return this},setBlack:function(a){this.cmyk[3]=a;return this.setCMYK(cmyk)},setBlue:function(a){this.rgb[2]=a;return this.setRGB(this.rgb)},setBrightness:function(a){this.hsv[2]=
toxi.MathUtils.clip(a,0,1);return this.setHSV(this.hsv)},setCMYK:function(a,b,d,c){if(a instanceof Array){b=a[1];d=a[2];c=a[3];a=a[0]}this.cmyk[0]=a;this.cmyk[1]=b;this.cmyk[2]=d;this.cmyk[3]=c;this.rgb=toxi.color.TColor.cmykToRGB(this.cmyk[0],this.cmyk[1],this.cmyk[2],this.cmyk[3]);this.hsv=toxi.color.TColor.rgbToHSV(this.rgb[0],this.rgb[1],this.rgb[2]);return this},setCyan:function(a){this.cmyk[0]=a;return this.setCMYK(this.cmyk)},setGreen:function(a){this.rgb[1]=a;return this.setRGB(this.rgb)},
setHSV:function(a,b,d){if(a instanceof Array){b=a[1];d=a[2];a=a[0]}a=[a,b,d];this.hsv[0]=a[0]%1;this.hsv[0]<0&&this.hsv[0]++;this.hsv[1]=toxi.MathUtils.clip(a[1],0,1);this.hsv[2]=toxi.MathUtils.clip(a[2],0,1);this.rgb=toxi.color.TColor.hsvToRGB(this.hsv[0],this.hsv[1],this.hsv[2]);this.cmyk=toxi.color.TColor.rgbToCMYK(this.rgb[0],this.rgb[1],this.rgb[2]);return this},setHue:function(a){a%=1;a<0&&a++;this.hsv[0]=a;this.setHSV(this.hsv)},setMagenta:function(a){this.cmyk[1]=a;return this.setCMYK(this.cmyk)},
setRed:function(a){this.rgb[0]=a;return this.setRGB(this.rgb)},setRGB:function(a,b,d){if(a instanceof Array){b=a[1];d=a[2];a=a[0]}this.rgb[0]=toxi.MathUtils.clip(a,0,1);this.rgb[1]=toxi.MathUtils.clip(b,0,1);this.rgb[2]=toxi.MathUtils.clip(d,0,1);this.cmyk=toxi.color.TColor.rgbToCMYK(this.rgb[0],this.rgb[1],this.rgb[2]);this.hsv=toxi.color.TColor.rgbToHSV(this.rgb[0],this.rgb[1],this.rgb[2]);return this},setSaturation:function(a){this.hsv[1]=toxi.MathUtils.clip(a,0,1);return this.setHSV(this.hsv)},
-setYellow:function(a){this.cmyk[2]=a;return this.setCMYK(this.cmyk)},sub:function(a){return this.copy().subSelf(a)},subSelf:function(a){this.rgb[0]=toxi.MathUtils.max(this.rgb[0]-a.rgb[0],0);this.rgb[1]=toxi.MathUtils.max(this.rgb[1]-a.rgb[1],0);this.rgb[2]=toxi.MathUtils.max(this.rgb[2]-a.rgb[2],0);return this.setRGB(this.rgb)},toARGB:function(){return parseInt(this.rgb[0]*255)<<16|parseInt(this.rgb[1]*255)<<8|parseInt(this.rgb[2]*255)|parseInt(this._alpha*255)<<24},toCMYKAArray:function(a){if(a===
-undefined)a=[];a[0]=this.cmyk[0];a[1]=this.cmyk[1];a[2]=this.cmyk[2];a[3]=this._alpha;return a},toHex:function(){var a=dec2hex(this.toARGB());if(a.length>6)a=a.substring(2);return a},toHSVAArray:function(a){if(a===undefined)a=[];a[0]=this.hsv[0];a[1]=this.hsv[1];a[2]=this.hsv[2];a[3]=this._alpha;return a},toRGBAArray:function(a,b){if(a===undefined){a=[];b=0}a[b++]=this.rgb[0];a[b++]=this.rgb[1];a[b++]=this.rgb[2];a[b]=this._alpha;return a},toString:function(){return"toxi.color.TColor: rgb: "+this.rgb[0]+
-", "+this.rgb[1]+", "+this.rgb[2]+" hsv: "+this.hsv[0]+","+this.hsv[1]+","+this.hsv[2]+" cmyk: "+this.cmyk[0]+", "+this.cmyk[1]+","+this.cmyk[2]+","+this.cmyk[3]+" alpha: "+this._alpha},yellow:function(){return this.cmyk[2]}};toxi.color.TColor.INV60DEGREES=60/360;toxi.color.TColor.INV8BIT=1/255;toxi.color.TColor.EPS=0.0010;toxi.color.TColor.BLACK_POINT=0.08;toxi.color.TColor.WHITE_POINT=1;toxi.color.TColor.GREY_THRESHOLD=0.01;
-toxi.color.TColor.cmykToRGB=function(a,b,d,c,e){if(e===undefined)e=[0,0,0];e[0]=1-Math.min(1,a+c);e[1]=1-Math.min(1,b+c);e[2]=1-Math.min(1,d+c);return e};toxi.color.TColor.hexToRGB=function(a,b){if(b===undefined)b=[];a=a.charAt(0)=="#"?a.substring(1,7):a;b[0]=parseInt(a.substring(0,2),16)*toxi.color.TColor.INV8BIT;b[1]=parseInt(a.substring(2,4),16)*toxi.color.TColor.INV8BIT;b[2]=parseInt(a.substring(4,6),16)*toxi.color.TColor.INV8BIT;return b};
-toxi.color.TColor.hsvToRGB=function(a,b,d,c){if(c===undefined)c=[];if(b==0)c[0]=c[1]=c[2]=d;else{a/=toxi.color.TColor.INV60DEGREES;var e=parseInt(a),f=a-e;a=d*(1-b);var g=d*(1-b*f);b=d*(1-b*(1-f));if(e==0){c[0]=d;c[1]=b;c[2]=a}else if(e==1){c[0]=g;c[1]=d;c[2]=a}else if(e==2){c[0]=a;c[1]=d;c[2]=b}else if(e==3){c[0]=a;c[1]=g;c[2]=d}else if(e==4){c[0]=b;c[1]=a;c[2]=d}else{c[0]=d;c[1]=a;c[2]=g}}return c};
-toxi.color.TColor.labToRGB=function(a,b,d,c){if(c===undefined)c=[];a=(a+16)/116;b=b/500+a;d=a-d/200;c[0]=b;c[1]=a;c[2]=d;for(d=0;d<3;d++){a=Math.pow(c[d],3);c[d]=a>0.008856?a:(c[d]-16/116)/7.787}b=c[0]*0.95047;a=c[1];d=c[2]*1.08883;c[0]=b*3.2406+a*-1.5372+d*-0.4986;c[1]=b*-0.9689+a*1.8758+d*0.0415;c[2]=b*0.0557+a*-0.204+d*1.057;a=1/2.4;for(d=0;d<3;d++)c[d]=c[d]>0.0031308?1.055*Math.pow(c[d],a)-0.055:12.92*c[d];return c};
-toxi.color.TColor.newARGB=function(a){return toxi.color.TColor.newRGBA((a>>16&255)*toxi.color.TColor.INV8BIT,(a>>8&255)*toxi.color.TColor.INV8BIT,(a&255)*toxi.color.TColor.INV8BIT,(a>>>24)*toxi.color.TColor.INV8BIT)};toxi.color.TColor.newCMYK=function(a,b,d,c){return toxi.color.TColor.newCMYKA(a,b,d,c,1)};toxi.color.TColor.newCMYKA=function(a,b,d,c,e){var f=new TColor;f.setCMYK([a,b,d,c]);f.setAlpha(toxi.MathUtils.clip(e,0,1));return f};
-toxi.color.TColor.newGray=function(a){return toxi.color.TColor.newGrayAlpha(a,1)};toxi.color.TColor.newGrayAlpha=function(a,b){var d=new toxi.color.TColor;d.setRGB([a,a,a]);d.setAlpha(b);return d};toxi.color.TColor.newHex=function(a){var b=new toxi.color.TColor;b.setRGB(toxi.color.TColor.hexToRGB(a));b.setAlpha(1);return b};toxi.color.TColor.newHSV=function(a,b,d){return toxi.color.TColor.newHSVA(a,b,d,1)};
-toxi.color.TColor.newHSVA=function(a,b,d,c){var e=new toxi.color.TColor;e.setHSV(a,b,d);e.setAlpha(toxi.MathUtils.clip(c,0,1));return e};toxi.color.TColor.newRandom=function(){return toxi.color.TColor.newRGBA(Math.random(),Math.random(),Math.random(),1)};toxi.color.TColor.newRGB=function(a,b,d){return toxi.color.TColor.newRGBA(a,b,d,1)};toxi.color.TColor.newRGBA=function(a,b,d,c){var e=new toxi.color.TColor;e.setRGB([a,b,d]);e.setAlpha(toxi.MathUtils.clip(c,0,1));return e};
-toxi.color.TColor.rgbToCMYK=function(a,b,d,c){if(c===undefined)c=[];c[0]=1-a;c[1]=1-b;c[2]=1-d;c[3]=toxi.MathUtils.min(c[0],c[1],c[2]);c[0]=toxi.MathUtils.clip(c[0]-c[3],0,1);c[1]=toxi.MathUtils.clip(c[1]-c[3],0,1);c[2]=toxi.MathUtils.clip(c[2]-c[3],0,1);c[3]=toxi.MathUtils.clip(c[3],0,1);return c};toxi.color.TColor.rgbToHex=function(a,b,d){return dec2hex(toxi.MathUtils.clip(a,0,1)*255)+dec2hex(toxi.MathUtils.clip(b,0,1)*255)+dec2hex(toxi.MathUtils.clip(d,0,1)*255)};
-toxi.color.TColor.rgbToHSV=function(a,b,d,c){if(c===undefined)c=[];var e=0,f=0,g=toxi.MathUtils.max(a,b,d),h=g-toxi.MathUtils.min(a,b,d);if(g!=0)f=h/g;if(f!=0)e=a==g?(b-d)/h:b==g?2+(d-a)/h:4+(a-b)/h;e*=toxi.color.TColor.INV60DEGREES;if(e<0)e+=1;c[0]=e;c[1]=f;c[2]=g;return c};toxi.color.TColor.RED=toxi.color.TColor.newRGB(1,0,0);
-toxi.color.TColor.RYB_WHEEL=[new toxi.Vec2D(0,0),new toxi.Vec2D(15,8),new toxi.Vec2D(30,17),new toxi.Vec2D(45,26),new toxi.Vec2D(60,34),new toxi.Vec2D(75,41),new toxi.Vec2D(90,48),new toxi.Vec2D(105,54),new toxi.Vec2D(120,60),new toxi.Vec2D(135,81),new toxi.Vec2D(150,103),new toxi.Vec2D(165,123),new toxi.Vec2D(180,138),new toxi.Vec2D(195,155),new toxi.Vec2D(210,171),new toxi.Vec2D(225,187),new toxi.Vec2D(240,204),new toxi.Vec2D(255,219),new toxi.Vec2D(270,234),new toxi.Vec2D(285,251),new toxi.Vec2D(300,
-267),new toxi.Vec2D(315,282),new toxi.Vec2D(330,298),new toxi.Vec2D(345,329),new toxi.Vec2D(360,0)];toxi.color.TColor.GREEN=toxi.color.TColor.newRGB(0,1,0);toxi.color.TColor.BLUE=toxi.color.TColor.newRGB(0,0,1);toxi.color.TColor.CYAN=toxi.color.TColor.newRGB(0,1,1);toxi.color.TColor.MAGENTA=toxi.color.TColor.newRGB(1,0,1);toxi.color.TColor.YELLOW=toxi.color.TColor.newRGB(1,1,0);toxi.color.TColor.BLACK=toxi.color.TColor.newRGB(0,0,0);toxi.color.TColor.WHITE=toxi.color.TColor.newRGB(1,1,1);
+setYellow:function(a){this.cmyk[2]=a;return this.setCMYK(this.cmyk)},sub:function(a){return this.copy().subSelf(a)},subSelf:function(a){this.rgb[0]=toxi.MathUtils.max(this.rgb[0]-a.rgb[0],0);this.rgb[1]=toxi.MathUtils.max(this.rgb[1]-a.rgb[1],0);this.rgb[2]=toxi.MathUtils.max(this.rgb[2]-a.rgb[2],0);return this.setRGB(this.rgb)},toARGB:function(){var a=parseInt(this.rgb[0]*255,10),b=parseInt(this.rgb[1]*255,10),d=parseInt(this.rgb[2]*255,10),c=parseInt(this._alpha*255,10);return a<<16|b<<8|d|c<<24},
+toCMYKAArray:function(a){if(a===undefined)a=[];a[0]=this.cmyk[0];a[1]=this.cmyk[1];a[2]=this.cmyk[2];a[3]=this._alpha;return a},toHex:function(){var a=h(this.toARGB());if(a.length>6)a=a.substring(2);return a},toHSVAArray:function(a){if(a===undefined)a=[];a[0]=this.hsv[0];a[1]=this.hsv[1];a[2]=this.hsv[2];a[3]=this._alpha;return a},toRGBAArray:function(a,b){if(a===undefined){a=[];b=0}a[b++]=this.rgb[0];a[b++]=this.rgb[1];a[b++]=this.rgb[2];a[b]=this._alpha;return a},toString:function(){return"toxi.color.TColor: rgb: "+
+this.rgb[0]+", "+this.rgb[1]+", "+this.rgb[2]+" hsv: "+this.hsv[0]+","+this.hsv[1]+","+this.hsv[2]+" cmyk: "+this.cmyk[0]+", "+this.cmyk[1]+","+this.cmyk[2]+","+this.cmyk[3]+" alpha: "+this._alpha},yellow:function(){return this.cmyk[2]}};toxi.color.TColor.INV60DEGREES=60/360;toxi.color.TColor.INV8BIT=1/255;toxi.color.TColor.EPS=0.0010;toxi.color.TColor.BLACK_POINT=0.08;toxi.color.TColor.WHITE_POINT=1;toxi.color.TColor.GREY_THRESHOLD=0.01;toxi.color.TColor.cmykToRGB=function(a,b,d,c,e){if(e===undefined)e=
+[0,0,0];e[0]=1-Math.min(1,a+c);e[1]=1-Math.min(1,b+c);e[2]=1-Math.min(1,d+c);return e};toxi.color.TColor.hexToRGB=function(a,b){if(b===undefined)b=[];a=a.charAt(0)=="#"?a.substring(1,7):a;b[0]=parseInt(a.substring(0,2),16)*toxi.color.TColor.INV8BIT;b[1]=parseInt(a.substring(2,4),16)*toxi.color.TColor.INV8BIT;b[2]=parseInt(a.substring(4,6),16)*toxi.color.TColor.INV8BIT;return b};toxi.color.TColor.hsvToRGB=function(a,b,d,c){if(c===undefined)c=[];if(b===0)c[0]=c[1]=c[2]=d;else{a/=toxi.color.TColor.INV60DEGREES;
+var e=parseInt(a,10),f=a-e;a=d*(1-b);var g=d*(1-b*f);b=d*(1-b*(1-f));if(e===0){c[0]=d;c[1]=b;c[2]=a}else if(e==1){c[0]=g;c[1]=d;c[2]=a}else if(e==2){c[0]=a;c[1]=d;c[2]=b}else if(e==3){c[0]=a;c[1]=g;c[2]=d}else if(e==4){c[0]=b;c[1]=a;c[2]=d}else{c[0]=d;c[1]=a;c[2]=g}}return c};toxi.color.TColor.labToRGB=function(a,b,d,c){if(c===undefined)c=[];a=(a+16)/116;b=b/500+a;var e=a-d/200;d=0;c[0]=b;c[1]=a;c[2]=e;for(d=0;d<3;d++){a=Math.pow(c[d],3);c[d]=a>0.008856?a:(c[d]-16/116)/7.787}b=c[0]*0.95047;a=c[1];
+e=c[2]*1.08883;c[0]=b*3.2406+a*-1.5372+e*-0.4986;c[1]=b*-0.9689+a*1.8758+e*0.0415;c[2]=b*0.0557+a*-0.204+e*1.057;a=1/2.4;for(d=0;d<3;d++)c[d]=c[d]>0.0031308?1.055*Math.pow(c[d],a)-0.055:12.92*c[d];return c};toxi.color.TColor.newARGB=function(a){return toxi.color.TColor.newRGBA((a>>16&255)*toxi.color.TColor.INV8BIT,(a>>8&255)*toxi.color.TColor.INV8BIT,(a&255)*toxi.color.TColor.INV8BIT,(a>>>24)*toxi.color.TColor.INV8BIT)};toxi.color.TColor.newCMYK=function(a,b,d,c){return toxi.color.TColor.newCMYKA(a,
+b,d,c,1)};toxi.color.TColor.newCMYKA=function(a,b,d,c,e){var f=new toxi.color.TColor;f.setCMYK([a,b,d,c]);f.setAlpha(toxi.MathUtils.clip(e,0,1));return f};toxi.color.TColor.newGray=function(a){return toxi.color.TColor.newGrayAlpha(a,1)};toxi.color.TColor.newGrayAlpha=function(a,b){var d=new toxi.color.TColor;d.setRGB([a,a,a]);d.setAlpha(b);return d};toxi.color.TColor.newHex=function(a){var b=new toxi.color.TColor;b.setRGB(toxi.color.TColor.hexToRGB(a));b.setAlpha(1);return b};toxi.color.TColor.newHSV=
+function(a,b,d){return toxi.color.TColor.newHSVA(a,b,d,1)};toxi.color.TColor.newHSVA=function(a,b,d,c){var e=new toxi.color.TColor;e.setHSV(a,b,d);e.setAlpha(toxi.MathUtils.clip(c,0,1));return e};toxi.color.TColor.newRandom=function(){return toxi.color.TColor.newRGBA(Math.random(),Math.random(),Math.random(),1)};toxi.color.TColor.newRGB=function(a,b,d){return toxi.color.TColor.newRGBA(a,b,d,1)};toxi.color.TColor.newRGBA=function(a,b,d,c){var e=new toxi.color.TColor;e.setRGB([a,b,d]);e.setAlpha(toxi.MathUtils.clip(c,
+0,1));return e};toxi.color.TColor.rgbToCMYK=function(a,b,d,c){if(c===undefined)c=[];c[0]=1-a;c[1]=1-b;c[2]=1-d;c[3]=toxi.MathUtils.min(c[0],c[1],c[2]);c[0]=toxi.MathUtils.clip(c[0]-c[3],0,1);c[1]=toxi.MathUtils.clip(c[1]-c[3],0,1);c[2]=toxi.MathUtils.clip(c[2]-c[3],0,1);c[3]=toxi.MathUtils.clip(c[3],0,1);return c};toxi.color.TColor.rgbToHex=function(a,b,d){return h(toxi.MathUtils.clip(a,0,1)*255)+h(toxi.MathUtils.clip(b,0,1)*255)+h(toxi.MathUtils.clip(d,0,1)*255)};toxi.color.TColor.rgbToHSV=function(a,
+b,d,c){if(c===undefined)c=[];var e=0,f=0,g=toxi.MathUtils.max(a,b,d),i=g-toxi.MathUtils.min(a,b,d);if(g!==0)f=i/g;if(f!==0)e=a==g?(b-d)/i:b==g?2+(d-a)/i:4+(a-b)/i;e*=toxi.color.TColor.INV60DEGREES;if(e<0)e+=1;c[0]=e;c[1]=f;c[2]=g;return c};toxi.color.TColor.RED=toxi.color.TColor.newRGB(1,0,0);toxi.color.TColor.RYB_WHEEL=[new toxi.Vec2D(0,0),new toxi.Vec2D(15,8),new toxi.Vec2D(30,17),new toxi.Vec2D(45,26),new toxi.Vec2D(60,34),new toxi.Vec2D(75,41),new toxi.Vec2D(90,48),new toxi.Vec2D(105,54),new toxi.Vec2D(120,
+60),new toxi.Vec2D(135,81),new toxi.Vec2D(150,103),new toxi.Vec2D(165,123),new toxi.Vec2D(180,138),new toxi.Vec2D(195,155),new toxi.Vec2D(210,171),new toxi.Vec2D(225,187),new toxi.Vec2D(240,204),new toxi.Vec2D(255,219),new toxi.Vec2D(270,234),new toxi.Vec2D(285,251),new toxi.Vec2D(300,267),new toxi.Vec2D(315,282),new toxi.Vec2D(330,298),new toxi.Vec2D(345,329),new toxi.Vec2D(360,0)];toxi.color.TColor.GREEN=toxi.color.TColor.newRGB(0,1,0);toxi.color.TColor.BLUE=toxi.color.TColor.newRGB(0,0,1);toxi.color.TColor.CYAN=
+toxi.color.TColor.newRGB(0,1,1);toxi.color.TColor.MAGENTA=toxi.color.TColor.newRGB(1,0,1);toxi.color.TColor.YELLOW=toxi.color.TColor.newRGB(1,1,0);toxi.color.TColor.BLACK=toxi.color.TColor.newRGB(0,0,0);toxi.color.TColor.WHITE=toxi.color.TColor.newRGB(1,1,1)})();
View
424 build/toxi-core.js
213 additions, 211 deletions not shown
View
32 build/toxi-physics2d.js
@@ -1,7 +1,6 @@
-// toxi-physics2d.js r38 - 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);console.log("undefined")};
-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}toxi.Vec2D.apply(this,[a,b]);this.isLocked=false;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 r40 - 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}toxi.Vec2D.apply(this,[a,b]);this.isLocked=false;this.prev=new toxi.Vec2D(this);this.temp=new toxi.Vec2D;c=c||1;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)}};
toxi.physics2d.VerletParticle2D.prototype.applyConstraints=function(){if(this.constraints!==undefined){var a=0;for(a=0;a<this.constraints.length;a++)this.constraints[a].applyConstraint(this)}};toxi.physics2d.VerletParticle2D.prototype.clearForce=function(){this.force.clear();return this};toxi.physics2d.VerletParticle2D.prototype.clearVelocity=function(){this.prev.set(this);return this};toxi.physics2d.VerletParticle2D.prototype.getInvWeight=function(){return this.invWeight};
toxi.physics2d.VerletParticle2D.prototype.getPreviousPosition=function(){return this.prev};toxi.physics2d.VerletParticle2D.prototype.getVelocity=function(){return this.sub(this.prev)};toxi.physics2d.VerletParticle2D.prototype.getWeight=function(){return this.weight};toxi.physics2d.VerletParticle2D.prototype.lock=function(){this.isLocked=true;return this};toxi.physics2d.VerletParticle2D.prototype.removeAllBehaviors=function(){this.behaviors=[];return this};
@@ -14,22 +13,23 @@ 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.force=a;this.scaleForce=new toxi.Vec2D;this.timeStep=0};
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},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){toxi.physics2d.ConstantForceBehavior.apply(this,[a])};toxi.extend(toxi.physics2d.GravityBehavior,toxi.physics2d.ConstantForceBehavior);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=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.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,10)!=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)}}};
+(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 e=this.createSingleParticle(v,d);this.particles.push(e);a.addParticle(e)}return this.particles}})();
+toxi.physics2d.ParticleString2D=function(){var a={physics:undefined,plist:undefined,pos:undefined,step:undefined,num:undefined,mass:undefined,strength:undefined},b=false;if(arguments.length===0)throw Error("Incorrect Parameters");else if(arguments.length==1){var c=arguments[0],d;for(d in c)a[d]=c[d]}else{a.physics=arguments[0];if(arguments.length==6){a.pos=arguments[1];a.step=arguments[2];a.num=arguments[3];a.mass=arguments[4];a.strength=arguments[5]}else{a.plist=arguments[1];a.strength=arguments[2]}}if(a.num!==
+undefined&&a.pos!==undefined&&a.step!==undefined&&a.mass!==undefined)b=true;if(!b&&a.plist===undefined)throw Error("Incorrect Parameters, please supply plist or num, pos, step & mass");this.physics=a.physics;this.links=[];var e;c=0;if(b){var f=a.pos.copy(),g=a.step,h=a.mass,i=g.magnitude();this.particles=[];d=a.strength;for(c=0;c<a.num;c++){b=new toxi.physics2d.VerletParticle2D(f.copy(),h);this.particles.push(b);this.physics.particles.push(b);if(e!==undefined){e=this.createSpring(e,b,i,d);this.links.push(e);
+this.physics.addSpring(e)}e=b;f.addSelf(g)}}else{d=a.strength;this.particles=a.plist||[];for(c=0;c<this.particles.length;c++){b=this.particles[c];this.physics.addParticle(b);if(e!==undefined){e=this.createSpring(e,b,e.distanceTo(b),d);this.links.push(e);this.physics.addSpring(e)}e=b}}};
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,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.PullBackString2D=function(a,b,c){toxi.physics2d.VerletSpring2D.apply(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,e){toxi.physics2d.VerletSpring2D.call(this,a,b,c,d);this.limit=e===undefined?Number.MAX_VALUE:e};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)};
-toxi.physics2d.VerletPhysics2D=function(a,b,c,d){this.behaviors=[];this.particles=[];this.springs=[];this.numIterations=b===undefined?50:b;this.timeStep=d===undefined?1:d;this.setDrag(c||0);a!==undefined&&this.addBehavior(new toxi.physics2d.GravityBehavior(a))};toxi.physics2d.VerletPhysics2D.addConstraintToAll=function(a,b){for(var c=0;c<b.length;c++)b[c].addConstraint(a)};toxi.physics2d.VerletPhysics2D.removeConstraintFromAll=function(a,b){for(var c=0;c<b.length;c++)b[c].removeConstraint(a)};
-toxi.physics2d.VerletPhysics2D.prototype={addBehavior:function(a){if(a===undefined)throw{name:"TypeError",message:"Incorrect Parameters for toxi.physics2d.VerletPhysics2D addBehavior"};a.configure(this.timeStep);this.behaviors.push(a)},addParticle:function(a){this.particles.push(a);return this},addSpring:function(a){this.getSpring(a.a,a.b)===undefined&&this.springs.push(a);return this},clear:function(){this.particles=[];this.springs=[];return this},constrainToBounds:function(){var a=undefined,b=0;
-for(b=0;b<this.particles.length;b++){a=this.particles[b];a.bounds!==undefined&&a.constrain(a.bounds)}if(this.worldBounds!==undefined)for(b=0;b<this.particles.length;b++){a=this.particles[b];a.constrain(this.worldBounds)}},getCurrentBounds:function(){var a=new toxi.Vec2D(Number.MAX_VALUE,Number.MAX_VALUE),b=new toxi.Vec2D(Number.MIN_VALUE,Number.MIN_VALUE),c=0,d=undefined;for(c=0;c<this.particles.length;c++){d=this.particles[c];a.minSelf(d);b.maxSelf(d)}return new toxi.Rect(a,b)},getDrag:function(){return 1-
-this.drag},getNumIterations:function(){return this.numIterations},getSpring:function(a,b){var c=0;for(c=0;c<this.springs.length;c++){var d=this.springs[c];if(d.a===a&&d.b===b||d.a===b&&d.b===b)return d}},getTimeStep:function(){return this.timeStep},getWorldBounds:function(){return this.worldBounds},removeBehavior:function(a){return toxi.physics2d.removeItemFrom(a,this.behaviors)},removeParticle:function(a){return toxi.physics2d.removeItemFrom(a,this.particles)},removeSpring:function(a){return toxi.physics2d.removeItemFrom(a,
-this.springs)},removeSpringElements:function(a){if(this.removeSpring(a)!==undefined)return this.removeParticle(a.a)&&this.removeParticle(a.b);return false},setDrag:function(a){this.drag=1-a},setNumIterations:function(a){this.numIterations=a},setTimeStep:function(a){this.timeStep=a;var b=0;for(b=0;b<this.behaviors.length;b++)this.behaviors[b].configure(a)},setWorldBounds:function(a){this.worldBounds=a;return this},update:function(){this.updateParticles();this.updateSprings();this.constrainToBounds();
-return this},updateParticles:function(){var a=0,b=0,c=undefined,d=undefined;for(a=0;a<this.behaviors.length;a++){c=this.behaviors[a];for(b=0;b<this.particles.length;b++){d=this.particles[b];c.applyBehavior(d)}}for(b=0;b<this.particles.length;b++){d=this.particles[b];d.scaleVelocity(this.drag);d.update()}},updateSprings:function(){var a=0,b=0;for(a=this.numIterations;a>0;a--)for(b=0;b<this.springs.length;b++)this.springs[b].update(a===1)}};
+toxi.physics2d.VerletPhysics2D=function(a,b,c,d){this.behaviors=[];this.particles=[];this.springs=[];this.numIterations=b||50;this.timeStep=d||1;this.setDrag(c||0);a!==undefined&&this.addBehavior(new toxi.physics2d.GravityBehavior(a))};toxi.physics2d.VerletPhysics2D.addConstraintToAll=function(a,b){for(var c=0;c<b.length;c++)b[c].addConstraint(a)};toxi.physics2d.VerletPhysics2D.removeConstraintFromAll=function(a,b){for(var c=0;c<b.length;c++)b[c].removeConstraint(a)};
+toxi.physics2d.VerletPhysics2D.prototype={addBehavior:function(a){a.configure(this.timeStep);this.behaviors.push(a)},addParticle:function(a){this.particles.push(a);return this},addSpring:function(a){this.getSpring(a.a,a.b)===undefined&&this.springs.push(a);return this},clear:function(){this.particles=[];this.springs=[];return this},constrainToBounds:function(){var a,b=0;for(b=0;b<this.particles.length;b++){a=this.particles[b];a.bounds!==undefined&&a.constrain(a.bounds)}if(this.worldBounds!==undefined)for(b=
+0;b<this.particles.length;b++){a=this.particles[b];a.constrain(this.worldBounds)}},getCurrentBounds:function(){var a=new toxi.Vec2D(Number.MAX_VALUE,Number.MAX_VALUE),b=new toxi.Vec2D(Number.MIN_VALUE,Number.MIN_VALUE),c=0,d;for(c=0;c<this.particles.length;c++){d=this.particles[c];a.minSelf(d);b.maxSelf(d)}return new toxi.Rect(a,b)},getDrag:function(){return 1-this.drag},getNumIterations:function(){return this.numIterations},getSpring:function(a,b){var c=0;for(c=0;c<this.springs.length;c++){var d=
+this.springs[c];if(d.a===a&&d.b===b||d.a===b&&d.b===b)return d}},getTimeStep:function(){return this.timeStep},getWorldBounds:function(){return this.worldBounds},removeBehavior:function(a){return toxi.physics2d.removeItemFrom(a,this.behaviors)},removeParticle:function(a){return toxi.physics2d.removeItemFrom(a,this.particles)},removeSpring:function(a){return toxi.physics2d.removeItemFrom(a,this.springs)},removeSpringElements:function(a){if(this.removeSpring(a)!==undefined)return this.removeParticle(a.a)&&
+this.removeParticle(a.b);return false},setDrag:function(a){this.drag=1-a},setNumIterations:function(a){this.numIterations=a},setTimeStep:function(a){this.timeStep=a;var b=0;for(b=0;b<this.behaviors.length;b++)this.behaviors[b].configure(a)},setWorldBounds:function(a){this.worldBounds=a;return this},update:function(){this.updateParticles();this.updateSprings();this.constrainToBounds();return this},updateParticles:function(){var a=0,b=0,c,d;for(a=0;a<this.behaviors.length;a++){c=this.behaviors[a];for(b=
+0;b<this.particles.length;b++){d=this.particles[b];c.applyBehavior(d)}}for(b=0;b<this.particles.length;b++){d=this.particles[b];d.scaleVelocity(this.drag);d.update()}},updateSprings:function(){var a=0,b=0;for(a=this.numIterations;a>0;a--)for(b=0;b<this.springs.length;b++)this.springs[b].update(a===1)}};
View
527 build/toxiclibs.js
264 additions, 263 deletions not shown
View
941 build/uncompressed/toxi-color-debug.js
@@ -0,0 +1,941 @@
+// uncompressed/toxi-color-debug r40 - http://github.com/hapticdata/toxiclibsjs
+toxi.color = toxi.color || {};
+(function(){
+
+ //private
+ //http://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hex-in-javascript
+ //TLDR: not as straightforward as i.toString(16)
+ var dec2hex = function(i) {
+ var result = "0000";
+ if (i >= 0 && i <= 15) { result = "000" + i.toString(16); }
+ else if (i >= 16 && i <= 255) { result = "00" + i.toString(16); }
+ else if (i >= 256 && i <= 4095) { result = "0" + i.toString(16); }
+ else if (i >= 4096 && i <= 65535) { result = i.toString(16); }
+ return result;
+ };
+
+ toxi.color.TColor = function(tcolor){
+ this.rgb = new Array(3);
+ this.hsv = new Array(3);
+ this.cmyk = new Array(4);
+ this._alpha = 1.0;
+ if(tcolor !== undefined){
+ var buffer = tcolor.toCMYKAArray();
+ this.cmyk = buffer.splice(0,4);
+ this.hsv = tcolor.toHSVAArray().splice(0,3);
+ this.rgb = tcolor.toRGBAArray().splice(0,3);
+ this._alpha = tcolor._alpha;
+ }
+ };
+
+ toxi.color.TColor.prototype = {
+
+ add: function(c){
+ return this.copy().addSelf(c);
+ },
+
+ addSelf: function(c) {
+ this.rgb[0] = toxi.MathUtils.min(this.rgb[0] + c.rgb[0], 1);
+ this.rgb[1] = toxi.MathUtils.min(this.rgb[1] + c.rgb[1], 1);
+ this.rgb[2] = toxi.MathUtils.min(this.rgb[2] + c.rgb[2], 1);
+ return this.setRGB(rgb);
+ },
+
+ /**
+ * Changes the brightness of the color by the given amount in the direction
+ * towards either the black or white point (depending on if current
+ * brightness >= 50%)
+ *
+ * @param amount
+ * @return itself
+ */
+ adjustConstrast: function(amount) {
+ return this.hsv[2] < 0.5 ? this.darken(amount) : this.lighten(amount);
+ },
+
+
+ /**
+ * Adds the given HSV values as offsets to the current color. Hue will
+ * automatically wrap.
+ *
+ * @param h
+ * @param s
+ * @param v
+ * @return itself
+ */
+ adjustHSV: function(h, s, v) {
+ return this.setHSV([ this.hsv[0] + h, this.hsv[1] + s, this.hsv[2] + v ]);
+ },
+
+ /**
+ * Adds the given RGB values as offsets to the current color. TColor will
+ * clip at black or white.
+ *
+ * @param r
+ * @param g
+ * @param b
+ * @return itself
+ */
+ adjustRGB: function(r, g,b) {
+ return this.setRGB([this.rgb[0] + r, this.rgb[1] + g, this.rgb[2] + b]);
+ },
+
+ alpha:function(){
+ return this._alpha;
+ },
+
+ /**
+ * Rotates this color by a random amount (not exceeding the one specified)
+ * and creates variations in saturation and brightness based on the 2nd
+ * parameter.
+ *
+ * @param theta
+ * max. rotation angle (in radians)
+ * @param delta
+ * max. sat/bri variance
+ * @return itself
+ */
+ analog: function(theta, delta) {
+ var angle = toxi.MathUtils.degrees(theta);
+ this.rotateRYB(angle * toxi.MathUtils.normalizedRandom());
+ this.hsv[1] += delta * toxi.MathUtils.normalizedRandom();
+ this.hsv[2] += delta * toxi.MathUtils.normalizedRandom();
+ return this.setHSV(this.hsv);
+ },
+
+ //shouldnt this be this.cmyk[3]?
+ black: function(){
+ return this.cmyk[3];
+ },
+ /**
+ * Blends the color with the given one by the stated amount
+ *
+ * @param c
+ * target color
+ * @param t
+ * interpolation factor
+ * @return itself
+ */
+ blend: function(c, t) {
+ if(t === undefined) { t = 0.5; }
+ var crgb = c.toRGBAArray();
+ this.rgb[0] += (crgb[0] - this.rgb[0]) * t;
+ this.rgb[1] += (crgb[1] - this.rgb[1]) * t;
+ this.rgb[2] += (crgb[2] - this.rgb[2]) * t;
+ this._alpha += (c.alpha() - this._alpha) * t;
+ 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(step){
+ this.hsv[2] = toxi.MathUtils.clip((this.hsv[2] -step), 0, 1);
+ return this.setHSV(this.hsv);
+ },
+ /**
+ Reduced the color's saturation by the given amount.
+ @param step
+ @return itself
+ */
+ desaturate: function(step) {
+ this.hsv[1] = toxi.MathUtils.clip((this.hsv[1] - step), 0, 1);
+ return this.setHSV(this.hsv);
+ },
+
+ differenceTo: function(c) {
+ return toxi.color.TColor.newRGB(Math.abs(this.rgb[0] - c.rgb[0]),
+ Math.abs(this.rgb[1] - c.rgb[1]),
+ Math.abs(this.rgb[2] - c.rgb[2]));
+ },
+
+ distanceToCMYK: function(c) {
+ var ccmyk = c.toCMYKAArray();
+ var dc = this.cmyk[0] - ccmyk[0];
+ var dm = this.cmyk[1] - ccmyk[1];
+ var dy = this.cmyk[2] - ccmyk[2];
+ var dk = this.cmyk[3] - ccmyk[3];
+ return Math.sqrt(dc * dc + dm * dm + dy * dy + dk * dk);
+ },
+
+ distanceToHSV: function(c) {
+ var hue = this.hsv[0] * toxi.MathUtils.TWO_PI;
+ var hue2 = c.hue() * toxi.MathUtils.TWO_PI;
+ var v1 =
+ new toxi.Vec3D((Math.cos(hue) * this.hsv[1]),
+ (Math.sin(hue) * this.hsv[1]), this.hsv[2]);
+ var v2 =
+ new toxi.Vec3D((Math.cos(hue2) * c.saturation()),
+ (Math.sin(hue2) * c.saturation()), c.brightness());
+ return v1.distanceTo(v2);
+ },
+
+ distanceToRGB: function(c) {
+ var crgb = c.toRGBAArray();
+ var dr = this.rgb[0] - crgb[0];
+ var dg = this.rgb[1] - crgb[1];
+ var db = this.rgb[2] - crgb[2];
+ return Math.sqrt(dr * dr + dg * dg + db * db);
+ },
+
+ equals: function(o) {
+ if (o !== undefined && o instanceof toxi.color.TColor) {
+ var c = o;
+ var dr = c.rgb[0] - this.rgb[0];
+ var dg = c.rgb[1] - this.rgb[1];
+ var db = c.rgb[2] - this.rgb[2];
+ var da = c.alpha() - this._alpha;
+ var d = Math.sqrt(dr * dr + dg * dg + db * db + da * da);
+ return d < toxi.color.TColor.EPS;
+ }
+ return false;
+ },
+
+ getAnalog: function(theta,delta) {
+ return new toxi.color.TColor(this).analog(theta, delta);
+ },
+
+ getBlended: function(c,t) {
+ return new toxi.color.TColor(this).blend(c, t);
+ },
+
+ /*getClosestHue: function(primaryOnly) {
+ return Hue.getClosest(hsv[0], false,primaryOnly);
+ },*/
+
+ getComplement: function() {
+ return new toxi.color.TColor(this).complement();
+ },
+
+ getComponentValue: function(criteria) {
+ return criteria.getComponentValueFor(this);
+ },
+
+ getDarkened: function(step) {
+ return new toxi.color.TColor(this).darken(step);
+ },
+
+ getDesaturated: function(step) {
+ return new toxi.color.TColor(this).desaturate(step);
+ },
+
+ getDifferenceTo: function(c) {
+ return this.copy().differenceTo(c);
+ },
+
+ getInverted: function() {
+ return new toxi.color.TColor(this).invert();
+ },
+
+ getLightened: function(step) {
+ return new toxi.color.TColor(this).lighten(step);
+ },
+
+ getRotatedRYB: function(theta) {
+ return new toxi.color.TColor(this).rotateRYB(theta);
+ },
+
+ getSaturated: function(step) {
+ return new toxi.color.TColor(this).saturate(step);
+ },
+
+ green: function() {
+ return this.rgb[1];
+ },
+
+ hue: function() {
+ return this.hsv[0];
+ },
+
+ invert: function() {
+ this.rgb[0] = 1 - this.rgb[0];
+ this.rgb[1] = 1 - this.rgb[1];
+ this.rgb[2] = 1 - this.rgb[2];
+ return this.setRGB(this.rgb);
+ },
+
+ isBlack: function() {
+ return (this.rgb[0] <= toxi.color.TColor.BLACK_POINT && ((this.rgb[0]==this.rgb[1]) && this.rgb[0] == this.rgb[2]));
+ },
+
+ isGrey:function() {
+ return this.hsv[1] < toxi.color.TColor.GREY_THRESHOLD;
+ },
+ /*
+ isPrimary:function() {
+ return Hue.isPrimary(this.hsv[0]);
+ },*/
+
+ isWhite: function() {
+ return (this.rgb[0] >= toxi.color.TColor.WHITE_POINT && (this.rgb[0] == this.rgb[1]) && (this.rgb[0] == this.rgb[2]));
+ },
+
+ lighten: function(step) {
+ this.hsv[2] = toxi.MathUtils.clip(this.hsv[2] + step, 0, 1);
+ return this.setHSV(this.hsv);
+ },
+
+ luminance: function() {
+ return this.rgb[0] * 0.299 + this.rgb[1] * 0.587 + this.rgb[2] * 0.114;
+ },
+
+ magenta: function() {
+ return this.cmyk[1];
+ },
+
+ red: function() {
+ return this.rgb[0];
+ },
+
+ rotateRYB: function(theta) {
+ var deg = parseInt(toxi.MathUtils.degrees(theta),10),
+ h = this.hsv[0] * 360,
+ i = 0,
+ p,
+ q;
+ theta %= 360;
+
+ var resultHue = 0;
+ for (i = 0; i < toxi.color.TColor.RYB_WHEEL.length - 1; i++) {
+ p = toxi.color.TColor.RYB_WHEEL[i];
+ q = toxi.color.TColor.RYB_WHEEL[i + 1];
+ if (q.y < p.y) {
+ q.y += 360;
+ }
+ if (p.y <= h && h <= q.y) {
+ resultHue = p.x + (q.x - p.x) * (h - p.y) / (q.y - p.y);
+ break;
+ }
+ }
+
+ // And the user-given angle (e.g. complement).
+ resultHue = (resultHue + theta) % 360;
+
+ // For the given angle, find out what hue is
+ // located there on the artistic color wheel.
+ for (i = 0; i < toxi.color.TColor.RYB_WHEEL.length - 1; i++) {
+ p = toxi.color.TColor.RYB_WHEEL[i];
+ q = toxi.color.TColor.RYB_WHEEL[i + 1];
+ if (q.y < p.y) {
+ q.y += 360;
+ }
+ if (p.x <= resultHue && resultHue <= q.x) {
+ h = p.y + (q.y - p.y) * (resultHue - p.x) / (q.x - p.x);
+ break;
+ }
+ }
+
+ this.hsv[0] = (h % 360) / 360.0;
+ return this.setHSV(this.hsv);
+
+ },
+
+ saturate: function(step) {
+ this.hsv[1] = toxi.MathUtils.clip(this.hsv[1] + step, 0, 1);
+ return this.setHSV(this.hsv);
+ },
+
+ saturation: function() {
+ return this.hsv[1];
+ },
+
+ setAlpha: function(alpha) {
+ this._alpha = alpha;
+ return this;
+ },
+
+ setARGB: function(argb) {
+ this.setRGB(((argb >> 16) & 0xff) * toxi.TColor.INV8BIT, ((argb >> 8) & 0xff) * toxi.TColor.INV8BIT, (argb & 0xff) * toxi.TColor.INV8BIT);
+ this._alpha = (argb >>> 24) * toxi.TColor.INV8BIT;
+ return this;
+ },
+
+ setBlack: function(val) {
+ this.cmyk[3] = val;
+ return this.setCMYK(cmyk);
+ },
+
+ setBlue: function(blue) {
+ this.rgb[2] = blue;
+ return this.setRGB(this.rgb);
+ },
+
+ setBrightness: function(brightness) {
+ this.hsv[2] = toxi.MathUtils.clip(brightness, 0, 1);
+ return this.setHSV(this.hsv);
+ },
+
+ setCMYK: function(c,m,y,k) {
+ //if it was passed in as an array instead of separate values
+ if(c instanceof Array){
+ m = c[1];
+ y = c[2];
+ k = c[3];
+ c = c[0];
+ }
+ this.cmyk[0] = c;
+ this.cmyk[1] = m;
+ this.cmyk[2] = y;
+ this.cmyk[3] = k;
+ this.rgb = toxi.color.TColor.cmykToRGB(this.cmyk[0],this.cmyk[1],this.cmyk[2],this.cmyk[3]);
+ this.hsv = toxi.color.TColor.rgbToHSV(this.rgb[0],this.rgb[1],this.rgb[2]);
+ return this;
+ },
+
+ /*setComponent(AccessCriteria criteria, float val) {
+ criteria.setComponentValueFor(this, val);
+ return this;
+ }*/
+
+ setCyan: function(val) {
+ this.cmyk[0] = val;
+ return this.setCMYK(this.cmyk);
+ },
+
+ setGreen: function(green) {
+ this.rgb[1] = green;
+ return this.setRGB(this.rgb);
+ },
+
+ setHSV: function(h,s,v) {
+ if(h instanceof Array){
+ s = h[1];
+ v = h[2];
+ h = h[0];
+ }
+ var newHSV = [h,s,v];
+ this.hsv[0] = newHSV[0] % 1;
+ if (this.hsv[0] < 0) {
+ this.hsv[0]++;
+ }
+ this.hsv[1] = toxi.MathUtils.clip(newHSV[1], 0, 1);
+ this.hsv[2] = toxi.MathUtils.clip(newHSV[2], 0, 1);
+ this.rgb = toxi.color.TColor.hsvToRGB(this.hsv[0], this.hsv[1], this.hsv[2]);
+ this.cmyk = toxi.color.TColor.rgbToCMYK(this.rgb[0], this.rgb[1], this.rgb[2]);
+ return this;
+ },
+
+ setHue: function(hue) {
+ hue %= 1.0;
+ if (hue < 0.0) {
+ hue++;
+ }
+ this.hsv[0] = hue;
+ this.setHSV(this.hsv);
+ },
+
+ setMagenta: function(val) {
+ this.cmyk[1] = val;
+ return this.setCMYK(this.cmyk);
+ },
+
+ setRed: function(red) {
+ this.rgb[0] = red;
+ return this.setRGB(this.rgb);
+ },
+
+ setRGB: function(r,g,b) {
+ if(r instanceof Array)
+ {
+ g = r[1];
+ b = r[2];
+ r = r[0];
+ }
+ this.rgb[0] = toxi.MathUtils.clip(r,0,1);
+ this.rgb[1] = toxi.MathUtils.clip(g,0,1);
+ this.rgb[2] = toxi.MathUtils.clip(b,0,1);
+ this.cmyk = toxi.color.TColor.rgbToCMYK(this.rgb[0], this.rgb[1], this.rgb[2]);
+ this.hsv = toxi.color.TColor.rgbToHSV(this.rgb[0], this.rgb[1], this.rgb[2]);
+ return this;
+ },
+
+ setSaturation: function(saturation) {
+ this.hsv[1] = toxi.MathUtils.clip(saturation, 0, 1);
+ return this.setHSV(this.hsv);
+ },
+
+ setYellow: function(val) {
+ this.cmyk[2] = val;
+ return this.setCMYK(this.cmyk);
+ },
+
+ sub: function(c) {
+ return this.copy().subSelf(c);
+ },
+
+ subSelf: function(c) {
+ this.rgb[0] = toxi.MathUtils.max(this.rgb[0] - c.rgb[0], 0);
+ this.rgb[1] = toxi.MathUtils.max(this.rgb[1] - c.rgb[1], 0);
+ this.rgb[2] = toxi.MathUtils.max(this.rgb[2] - c.rgb[2], 0);
+ return this.setRGB(this.rgb);
+ },
+
+ toARGB: function() {
+ var r = parseInt((this.rgb[0] * 255),10),
+ g = parseInt((this.rgb[1] * 255),10),
+ b = parseInt((this.rgb[2] * 255),10),
+ a = parseInt((this._alpha * 255),10);
+ return r << 16 | g << 8 | b | a << 24;
+ },
+
+ toCMYKAArray: function(cmyka) {
+ if (cmyka === undefined) {
+ cmyka = [];
+ }
+ cmyka[0] = this.cmyk[0];
+ cmyka[1] = this.cmyk[1];
+ cmyka[2] = this.cmyk[2];
+ cmyka[3] = this._alpha;
+ return cmyka;
+ },
+
+ toHex: function() {
+ var hex = dec2hex(this.toARGB());
+ if (hex.length > 6) {
+ hex = hex.substring(2);
+ }
+ return hex;
+ },
+
+ toHSVAArray: function(hsva) {
+ if (hsva === undefined) {
+ hsva = [];
+ }
+ hsva[0] = this.hsv[0];
+ hsva[1] = this.hsv[1];
+ hsva[2] = this.hsv[2];
+ hsva[3] = this._alpha;
+ return hsva;
+ },
+
+ /**
+ * to an Array of RGBA values
+ * @param rgba
+ * @param offset (optional)
+ * @return rgba array
+ */
+ toRGBAArray: function(rgba, offset) {
+ if (rgba === undefined) {
+ rgba = [];
+ offset = 0;
+ }
+ rgba[offset++] = this.rgb[0];
+ rgba[offset++] = this.rgb[1];
+ rgba[offset++] = this.rgb[2];
+ rgba[offset] = this._alpha;
+ return rgba;
+ },
+
+ toString: function(){
+ return "toxi.color.TColor: rgb: "+this.rgb[0] + ", " +this.rgb[1] + ", "+this.rgb[2]+
+ " hsv: "+ this.hsv[0] + ","+this.hsv[1]+","+this.hsv[2]+
+ " cmyk: "+this.cmyk[0] + ", "+this.cmyk[1]+","+this.cmyk[2]+","+this.cmyk[3]+
+ " alpha: "+this._alpha;
+ },
+
+ yellow: function() {
+ return this.cmyk[2];
+ }
+
+ };
+
+
+
+ toxi.color.TColor.INV60DEGREES = 60.0 / 360;
+ toxi.color.TColor.INV8BIT = 1.0 / 255;
+ toxi.color.TColor.EPS = 0.001;
+ /*
+ protected static final Vec2D[] RYB_WHEEL = new Vec2D[] { new Vec2D(0, 0),
+ new Vec2D(15, 8), new Vec2D(30, 17), new Vec2D(45, 26),
+ new Vec2D(60, 34), new Vec2D(75, 41), new Vec2D(90, 48),
+ new Vec2D(105, 54), new Vec2D(120, 60), new Vec2D(135, 81),
+ new Vec2D(150, 103), new Vec2D(165, 123), new Vec2D(180, 138),
+ new Vec2D(195, 155), new Vec2D(210, 171), new Vec2D(225, 187),
+ new Vec2D(240, 204), new Vec2D(255, 219), new Vec2D(270, 234),
+ new Vec2D(285, 251), new Vec2D(300, 267), new Vec2D(315, 282),
+ new Vec2D(330, 298), new Vec2D(345, 329), new Vec2D(360, 0) };
+ */
+
+ /**
+ * Maximum rgb component value for a color to be classified as black.
+ *
+ * @see #isBlack()
+ */
+ toxi.color.TColor.BLACK_POINT = 0.08;
+
+ /**
+ * Minimum rgb component value for a color to be classified as white.
+ *
+ * @see #isWhite()
+ */
+ toxi.color.TColor.WHITE_POINT = 1.0;
+
+ /**
+ * Maximum saturations value for a color to be classified as grey
+ *
+ * @see #isGrey()
+ */
+ toxi.color.TColor.GREY_THRESHOLD = 0.01;
+
+
+
+ /**
+ * Converts CMYK floats into an RGB array.
+ *
+ * @param c
+ * @param m
+ * @param y
+ * @param k
+ * @param rgb optional rgb array to populate
+ * @return rgb array
+ */
+ toxi.color.TColor.cmykToRGB = function(c,m,y,k,rgb) {
+ if(rgb ===undefined){
+ rgb = [0,0,0];
+ }
+ rgb[0] = 1.0 - Math.min(1.0, c + k);
+ rgb[1] = 1.0 - Math.min(1.0, m + k);
+ rgb[2] = 1.0 - Math.min(1.0, y + k);
+ return rgb;
+ };
+
+
+ /**
+ * Converts hex string into a RGB array.
+ *
+ * @param hexRGB
+ * @param rgb array optional
+ * @return rgb array
+ */
+ toxi.color.TColor.hexToRGB = function(hexRGB,rgb) {
+ if(rgb === undefined){ rgb = []; }
+ //var rgbInt = parseInt(hexRGB,16);
+ hexRGB = (hexRGB.charAt(0)=="#") ? hexRGB.substring(1,7):hexRGB;
+ rgb[0] = parseInt(hexRGB.substring(0,2),16) * toxi.color.TColor.INV8BIT;//((rgbInt >> 16) & 0xff) * toxi.color.TColor.INV8BIT;
+ rgb[1] = parseInt(hexRGB.substring(2,4),16) * toxi.color.TColor.INV8BIT;//((rgbInt >> 8) & 0xff) * toxi.color.TColor.INV8BIT;
+ rgb[2] = parseInt(hexRGB.substring(4,6),16) * toxi.color.TColor.INV8BIT;//((rgbInt & 0xff) * toxi.color.TColor.INV8BIT);
+ return rgb;
+ };
+
+
+ /**
+ * Converts HSV values into RGB array.
+ *
+ * @param h
+ * @param s
+ * @param v
+ * @param rgb array optional
+ * @return rgb array
+ */
+ toxi.color.TColor.hsvToRGB = function(h, s, v,rgb) {
+ if(rgb === undefined){ rgb = []; }
+ if(s === 0.0){
+ rgb[0] = rgb[1] = rgb[2] = v;
+ } else {
+ h /= toxi.color.TColor.INV60DEGREES;
+ var i = parseInt(h,10),
+ f = h - i,
+ p = v * (1 - s),
+ q = v * (1 - s * f),
+ t = v * (1 - s * (1 - f));
+
+ if (i === 0) {
+ rgb[0] = v;
+ rgb[1] = t;
+ rgb[2] = p;
+ } else if (i == 1) {
+ rgb[0] = q;
+ rgb[1] = v;
+ rgb[2] = p;
+ } else if (i == 2) {
+ rgb[0] = p;
+ rgb[1] = v;
+ rgb[2] = t;
+ } else if (i == 3) {
+ rgb[0] = p;
+ rgb[1] = q;
+ rgb[2] = v;
+ } else if (i == 4) {
+ rgb[0] = t;
+ rgb[1] = p;
+ rgb[2] = v;
+ } else {
+ rgb[0] = v;
+ rgb[1] = p;
+ rgb[2] = q;
+ }
+ }
+ return rgb;
+ };
+
+ /**
+ * Converts CIE Lab to RGB components.
+ *
+ * First we have to convert to XYZ color space. Conversion involves using a
+ * white point, in this case D65 which represents daylight illumination.
+ *
+ * Algorithm adopted from: http://www.easyrgb.com/math.php
+ *
+ * @param l
+ * @param a
+ * @param b
+ * @param rgb
+ * @return rgb array
+ */
+ toxi.color.TColor.labToRGB = function(l, a, b,rgb) {
+ if(rgb === undefined){ rgb = []; }
+ var y = (l + 16) / 116.0,
+ x = a / 500.0 + y,
+ z = y - b / 200.0,
+ i = 0;
+ rgb[0] = x;
+ rgb[1] = y;
+ rgb[2] = z;
+ for (i = 0; i < 3; i++) {
+ var p = Math.pow(rgb[i], 3);
+ if (p > 0.008856) {
+ rgb[i] = p;
+ } else {
+ rgb[i] = (rgb[i] - 16 / 116.0) / 7.787;
+ }
+ }
+
+ // Observer = 2, Illuminant = D65
+ x = rgb[0] * 0.95047;
+ y = rgb[1];
+ z = rgb[2] * 1.08883;
+
+ rgb[0] = x * 3.2406 + y * -1.5372 + z * -0.4986;
+ rgb[1] = x * -0.9689 + y * 1.8758 + z * 0.0415;
+ rgb[2] = x * 0.0557 + y * -0.2040 + z * 1.0570;
+ var tpow = 1 / 2.4;
+ for (i = 0; i < 3; i++) {
+ if (rgb[i] > 0.0031308) {
+ rgb[i] = (1.055 * Math.pow(rgb[i], tpow) - 0.055);
+ } else {
+ rgb[i] = 12.92 * rgb[i];
+ }
+ }
+ return rgb;
+ };
+
+ /**
+ * Factory method. Creates new color from ARGB int.
+ *
+ * @param argb
+ * @return new color
+ */
+ toxi.color.TColor.newARGB = function(argb) {
+ return toxi.color.TColor.newRGBA(((argb >> 16) & 0xff) * toxi.color.TColor.INV8BIT, ((argb >> 8) & 0xff) * toxi.color.TColor.INV8BIT, (argb & 0xff) * toxi.color.TColor.INV8BIT, (argb >>> 24) * toxi.color.TColor.INV8BIT);
+ };
+
+ /**
+ Factory method. Creates new color from CMYK values.
+ @param c
+ @param m
+ @param y
+ @param k
+ @return new color
+ */
+ toxi.color.TColor.newCMYK = function(c, m, y, k) {
+ return toxi.color.TColor.newCMYKA(c, m, y, k, 1);
+ };
+
+ /**
+ Factory method. Creates new color from CMYK + alpha values.
+ @param c
+ @param m
+ @param y
+ @param k
+ @param a
+ @return new color
+ */
+ toxi.color.TColor.newCMYKA = function(c, m, y, k, a) {
+ var col = new toxi.color.TColor();
+ col.setCMYK([c, m, y, k ]);
+ col.setAlpha(toxi.MathUtils.clip(a, 0, 1));
+ return col;
+ };
+
+ /**
+ Factory method. Creates a new shade of gray + alpha.
+ @param gray
+ @return new color.
+ */
+ toxi.color.TColor.newGray = function(gray) {
+ return toxi.color.TColor.newGrayAlpha(gray, 1);
+ };
+
+ toxi.color.TColor.newGrayAlpha = function(gray, alpha) {
+ var c = new toxi.color.TColor();
+ c.setRGB([gray, gray, gray ]);
+ c.setAlpha(alpha);
+ return c;
+ };
+
+ /**
+ Factory method. New color from hex string.
+ @param hexRGB
+ @return new color
+ */
+ toxi.color.TColor.newHex = function(hexRGB) {
+ var c = new toxi.color.TColor();
+ c.setRGB(toxi.color.TColor.hexToRGB(hexRGB));
+ c.setAlpha(1);
+ return c;
+ };
+
+ /**
+ Factory method. New color from hsv values.
+ @param h
+ @param s
+ @param v
+ @return new color
+ */
+ toxi.color.TColor.newHSV = function(h, s, v) {
+ return toxi.color.TColor.newHSVA(h, s, v, 1);
+ };
+
+
+ toxi.color.TColor.newHSVA = function(h, s,v,a) {
+ var c = new toxi.color.TColor();
+ c.setHSV(h, s, v);
+ c.setAlpha(toxi.MathUtils.clip(a, 0, 1));
+ return c;
+ };
+
+ /**
+ Factory method. Creates new random color. Alpha is always 1.0.
+ @return random color
+ */
+ toxi.color.TColor.newRandom = function() {
+ return toxi.color.TColor.newRGBA(Math.random(), Math.random(), Math.random(), 1);
+ };
+
+ /**
+ Factory method. Creates new color from RGB values. Alpha is set to 1.0.
+ @param r
+ @param g
+ @param b
+ @return new color
+ */
+ toxi.color.TColor.newRGB = function(r, g, b) {
+ return toxi.color.TColor.newRGBA(r, g, b, 1);
+ };
+
+ toxi.color.TColor.newRGBA = function( r, g, b, a) {
+ var c = new toxi.color.TColor();
+ c.setRGB([ r, g, b ]);
+ c.setAlpha(toxi.MathUtils.clip(a, 0, 1));
+ return c;
+ };
+
+ /**
+ Converts the RGB values into a CMYK array.
+ @param r
+ @param g
+ @param b
+ @param cmyk array optional
+ @return cmyk array
+ */
+ toxi.color.TColor.rgbToCMYK = function(r, g, b,cmyk) {
+ if(cmyk === undefined){ cmyk = []; }
+ cmyk[0] = 1 - r;
+ cmyk[1] = 1 - g;
+ cmyk[2] = 1 - b;
+ cmyk[3] = toxi.MathUtils.min(cmyk[0], cmyk[1], cmyk[2]);
+ cmyk[0] = toxi.MathUtils.clip(cmyk[0] - cmyk[3], 0, 1);
+ cmyk[1] = toxi.MathUtils.clip(cmyk[1] - cmyk[3], 0, 1);
+ cmyk[2] = toxi.MathUtils.clip(cmyk[2] - cmyk[3], 0, 1);
+ cmyk[3] = toxi.MathUtils.clip(cmyk[3], 0, 1);
+ return cmyk;
+ };
+
+
+ /**
+ Formats the RGB float values into hex integers.
+ @param r
+ @param g
+ @param b
+ @return hex string
+ */
+ toxi.color.TColor.rgbToHex = function(r, g, b) {
+ var hex = dec2hex(toxi.MathUtils.clip(r, 0, 1) * 0xff) + dec2hex(toxi.MathUtils.clip(g, 0, 1) * 0xff) + dec2hex(toxi.MathUtils.clip(b, 0, 1) * 0xff);
+ return hex;
+ };
+
+ /**
+ Converts the RGB values into an HSV array.
+ @param r
+ @param g
+ @param b
+ @param hsv optional
+ @return hsv array
+ */
+ toxi.color.TColor.rgbToHSV = function(r, g, b,hsv) {
+ if(hsv ===undefined){ hsv = []; }
+ var h = 0,
+ s = 0,
+ v = toxi.MathUtils.max(r, g, b),
+ d = v - toxi.MathUtils.min(r, g, b);
+
+ if (v !== 0) {
+ s = d / v;
+ }
+ if (s !== 0) {
+ if (r == v) {
+ h = (g - b) / d;
+ } else if (g == v) {
+ h = 2 + (b - r) / d;
+ } else {
+ h = 4 + (r - g) / d;
+ }
+ }
+ h *= toxi.color.TColor.INV60DEGREES;
+ if (h < 0) {
+ h += 1.0;
+ }
+ hsv[0] = h;
+ hsv[1] = s;
+ hsv[2] = v;
+ return hsv;
+ };
+
+ toxi.color.TColor.RED = toxi.color.TColor.newRGB(1, 0, 0);
+ toxi.color.TColor.RYB_WHEEL = [
+ new toxi.Vec2D(0, 0),
+ new toxi.Vec2D(15, 8), new toxi.Vec2D(30, 17), new toxi.Vec2D(45, 26),
+ new toxi.Vec2D(60, 34), new toxi.Vec2D(75, 41), new toxi.Vec2D(90, 48),
+ new toxi.Vec2D(105, 54), new toxi.Vec2D(120, 60), new toxi.Vec2D(135, 81),
+ new toxi.Vec2D(150, 103), new toxi.Vec2D(165, 123), new toxi.Vec2D(180, 138),
+ new toxi.Vec2D(195, 155), new toxi.Vec2D(210, 171), new toxi.Vec2D(225, 187),
+ new toxi.Vec2D(240, 204), new toxi.Vec2D(255, 219), new toxi.Vec2D(270, 234),
+ new toxi.Vec2D(285, 251), new toxi.Vec2D(300, 267), new toxi.Vec2D(315, 282),
+ new toxi.Vec2D(330, 298), new toxi.Vec2D(345, 329), new toxi.Vec2D(360, 0)
+ ];
+ toxi.color.TColor.GREEN = toxi.color.TColor.newRGB(0, 1, 0);
+ toxi.color.TColor.BLUE = toxi.color.TColor.newRGB(0, 0, 1);
+ toxi.color.TColor.CYAN = toxi.color.TColor.newRGB(0, 1, 1);
+ toxi.color.TColor.MAGENTA = toxi.color.TColor.newRGB(1, 0, 1);
+ toxi.color.TColor.YELLOW = toxi.color.TColor.newRGB(1, 1, 0);
+ toxi.color.TColor.BLACK = toxi.color.TColor.newRGB(0, 0, 0);
+ toxi.color.TColor.WHITE = toxi.color.TColor.newRGB(1, 1, 1);
+
+})();
View
7,315 build/uncompressed/toxi-core-debug.js
7,315 additions, 0 deletions not shown
View
816 build/uncompressed/toxi-physics2d-debug.js
@@ -0,0 +1,816 @@
+// uncompressed/toxi-physics2d-debug r40 - http://github.com/hapticdata/toxiclibsjs
+toxi.physics2d = toxi.physics2d || {};
+
+toxi.physics2d.removeItemFrom = function(item,array){
+ var index = array.indexOf(item);
+ if(index > -1){
+ return array.splice(index,1);
+ }
+ return undefined;
+};
+toxi.physics2d.VerletParticle2D = function(x,y,w){
+ this.force = new toxi.Vec2D();
+ if(x instanceof toxi.Vec2D){
+ if(x instanceof toxi.physics2d.VerletParticle2D){
+
+ y = x.y;
+ w = x.weight;
+ x = x.x;
+ this.isLocked = x.isLocked;
+
+ } else if(y === undefined){
+ y = x.y;
+ w = 1;
+ x = x.x;
+ } else {
+ w = y;
+ y = x.y;
+ x = x.x;
+ }
+ }
+ toxi.Vec2D.apply(this,[x,y]);
+ this.isLocked = false;
+ this.prev = new toxi.Vec2D(this);
+ this.temp = new toxi.Vec2D();
+ w = w || 1;
+ this.setWeight(w);
+};
+
+toxi.extend(toxi.physics2d.VerletParticle2D,toxi.Vec2D);
+
+toxi.physics2d.VerletParticle2D.prototype.addBehavior = function(behavior,timeStep){
+ if(this.behaviors === undefined){
+ this.behaviors = [];
+ }
+ if(behavior === undefined){
+ throw { name: "TypeError", message: "behavior was undefined"};
+ }
+ timeStep = (timeStep === undefined)? 1 : timeStep;
+ behavior.configure(timeStep);
+ this.behaviors.push(behavior);
+ return this;
+};
+
+toxi.physics2d.VerletParticle2D.prototype.addConstraint = function(c){
+ if(this.constraints === undefined){
+ this.constraints = [];
+ }
+ this.constraints.push(c);
+ return this;
+};
+
+toxi.physics2d.VerletParticle2D.prototype.addForce = function(f){
+ this.force.addSelf(f);
+ return this;
+};
+
+toxi.physics2d.VerletParticle2D.prototype.addVelocity = function(v){
+ this.prev.subSelf(v);
+ return this;
+};
+
+toxi.physics2d.VerletParticle2D.prototype.applyBehaviors = function(){
+ if(this.behaviors !== undefined){
+ var i = 0;
+ for(i = 0;i<this.behaviors.length;i++){
+ this.behaviors[i].applyBehavior(this);
+ }
+ }
+};
+
+toxi.physics2d.VerletParticle2D.prototype.applyConstraints = function(){
+ if(this.constraints !== undefined){
+ var i =0;
+ for(i =0;i<this.constraints.length;i++){
+ this.constraints[i].applyConstraint(this);
+ }
+ }
+};
+
+
+toxi.physics2d.VerletParticle2D.prototype.clearForce = function(){
+ this.force.clear();
+ return this;
+};
+
+toxi.physics2d.VerletParticle2D.prototype.clearVelocity = function(){
+ this.prev.set(this);
+ return this;
+};
+
+toxi.physics2d.VerletParticle2D.prototype.getInvWeight = function(){
+ return this.invWeight;
+};
+
+toxi.physics2d.VerletParticle2D.prototype.getPreviousPosition = function(){
+ return this.prev;
+};
+
+toxi.physics2d.VerletParticle2D.prototype.getVelocity = function(){
+ return this.sub(this.prev);
+};
+
+toxi.physics2d.VerletParticle2D.prototype.getWeight = function(){
+ return this.weight;
+};
+
+toxi.physics2d.VerletParticle2D.prototype.lock = function(){
+ this.isLocked = true;
+ return this;
+};
+
+toxi.physics2d.VerletParticle2D.prototype.removeAllBehaviors = function(){
+ this.behaviors = [];
+ return this;
+};
+
+toxi.physics2d.VerletParticle2D.prototype.removeAllConstraints = function(){
+ this.constraints = [];
+ return this;
+};
+
+toxi.physics2d.VerletParticle2D.prototype.removeBehavior = function(b){
+ return toxi.physics2d.removeItemFrom(b,this.behaviors);
+};
+
+toxi.physics2d.VerletParticle2D.prototype.removeConstraint = function(c){
+ return toxi.physics2d.removeItemFrom(c,this.constraints);
+};
+
+toxi.physics2d.VerletParticle2D.prototype.scaleVelocity = function(scl){
+ this.prev.interpolateToSelf(this,1 - scl);
+ return this;
+};
+
+toxi.physics2d.VerletParticle2D.prototype.setPreviousPosition = function(p){
+ this.prev.set(p);
+ return this;
+};
+
+toxi.physics2d.VerletParticle2D.prototype.setWeight = function(w){
+ this.weight = w;
+ this.invWeight = (w !== 0) ? 1 / w : 0; //avoid divide by zero
+};
+
+toxi.physics2d.VerletParticle2D.prototype.unlock = function() {
+ this.clearVelocity();
+ this.isLocked = false;
+ return this;
+};
+
+toxi.physics2d.VerletParticle2D.prototype.update = function(){
+
+ if(!this.isLocked){
+ var that = this;
+ this.applyBehaviors();
+ //applyForce protected
+ (function(){
+ that.temp.set(that);
+ that.addSelf(that.sub(that.prev).addSelf(that.force.scale(that.weight)));
+ that.prev.set(that.temp);
+ that.force.clear();
+ })();
+ this.applyConstraints();
+ }
+};
+toxi.physics2d.VerletSpring2D = function(a,b,len,str){
+ this.a = a;
+ this.b = b;
+ this.restLength = len;
+ this.strength = str;
+};
+
+toxi.physics2d.VerletSpring2D.EPS = 1e-6;
+
+toxi.physics2d.VerletSpring2D.prototype = {
+ getRestLength: function(){
+ return this.restLength;
+ },
+
+ getStrength: function(){
+ return this.strength;
+ },
+
+ lockA: function(s){
+ this.isALocked = s;
+ return this;
+ },
+
+ lockB: function(s){
+ this.isALocked = s;
+ return this;
+ },
+
+ setRestLength: function(len){
+ this.restLength = len;
+ this.restLengthSquared = len * len;
+ return this;
+ },
+
+ setStrength: function(strength){
+ this.strength = strength;
+ return this;
+ },
+
+ update: function(applyConstraints){ //protected
+ var delta = this.b.sub(this.a);
+ //add minute offset to avoid div-by-zero errors
+ var dist = delta.magnitude() + toxi.physics2d.VerletSpring2D.EPS;
+ var normDistStrength = (dist - this.restLength) / (dist * (this.a.invWeight + this.b.invWeight)) * this.strength;
+ if(!this.a.isLocked && !this.isALocked){
+ this.a.addSelf(
+ delta.scale(normDistStrength * this.a.invWeight)
+ );
+ if(applyConstraints){
+ this.a.applyConstraints();
+ }
+ }
+ if(!this.b.isLocked && !this.isBLocked){
+ this.b.addSelf(
+ delta.scale(-normDistStrength * this.b.invWeight)
+ );
+ if(applyConstraints){
+ this.b.applyConstraints();
+ }
+ }
+ }
+};toxi.physics2d.AttractionBehavior = function(attractor,radius,strength,jitter){
+ if(arguments.length < 3){
+ throw { name: "IncorrectParameters", message: "Constructor received incorrect Parameters"};
+ }
+ this.jitter = jitter || 0;
+ this.attractor = attractor;
+ this.strength = strength;
+ this.setRadius(radius);
+};
+
+toxi.physics2d.AttractionBehavior.prototype = {
+ applyBehavior: function(p){ //apply() is reserved, so this is now applyBehavior
+ var delta = this.attractor.sub(p);
+ var dist = delta.magSquared();
+ if(dist < this.radiusSquared){
+ var f = delta.normalizeTo((1.0 - dist / this.radiusSquared)).jitter(this.jitter).scaleSelf(this.attrStrength);
+ p.addForce(f);
+ }
+ },
+
+ configure: function(timeStep){
+ this.timeStep = timeStep;
+ this.setStrength(this.strength);
+ },
+
+ getAttractor: function(){
+ return this.attractor;
+ },
+
+ getJitter: function(){
+ return this.jitter;
+ },
+
+ getRadius: function(){
+ return this.radius;
+ },
+
+ getStrength: function(){
+ return this.strength;
+ },
+
+ setAttractor: function(attractor){
+ this.attractor = attractor;
+ },
+
+ setJitter: function(jitter){
+ this.jitter = jitter;
+ },
+
+ setRadius: function(r){
+ this.radius = r;
+ this.radiusSquared = r * r;
+ },
+
+ setStrength: function(strength){
+ this.strength = strength;
+ this.attrStrength = strength * this.timeStep;
+ }
+};
+
+//expected to implement ParticleBehavior interface
+
+toxi.physics2d.ConstantForceBehavior = function(force){
+ this.force = force;
+ this.scaleForce = new toxi.Vec2D();
+ this.timeStep = 0;
+};
+
+toxi.physics2d.ConstantForceBehavior.prototype = {
+ applyBehavior: function(p){ //apply() is reserved, so this is now applyBehavior
+ p.addForce(this.scaledForce);
+ },
+
+ configure: function(timeStep){
+ this.timeStep = timeStep;
+ this.setForce(this.force);
+ },
+
+ getForce: function(){
+ return this.force;
+ },
+
+ setForce: function(forceVec){
+ this.force = forceVec;
+ this.scaledForce = this.force.scale(this.timeStep);
+ },
+
+ toString: function(){
+ return "behavior force: "+ this.force+ " scaledForce: "+this.scaledForce+ " timeStep: "+this.timeStep;
+ }
+};
+toxi.physics2d.GravityBehavior = function(gravityVec){
+ toxi.physics2d.ConstantForceBehavior.apply(this,[gravityVec]);
+};
+
+toxi.extend(toxi.physics2d.GravityBehavior,toxi.physics2d.ConstantForceBehavior);
+
+toxi.physics2d.GravityBehavior.prototype.configure = function(timeStep){
+ this.timeStep = timeStep;
+ this.scaledForce = this.force.scale(timeStep * timeStep);
+};//either Vec2D + angle
+toxi.physics2d.AngularConstraint = function(theta_p,theta){
+
+ if(arguments.length > 1){
+ var p = theta_p;
+ this.theta = theta;
+ this.rootPos = new toxi.Vec2D(p);
+ } else {
+ this.rootPos = new toxi.Vec2D();
+ this.theta = theta_p;
+ }
+ if(parseInt(this.theta,10) != this.theta){
+ this.theta = toxi.MathUtils.radians(this.theta);
+ }
+};
+
+
+toxi.physics2d.AngularConstraint.prototype.applyConstraint = function(p){
+ var delta = p.sub(this.rootPos);
+ var heading = toxi.MathUtils.floor(delta.heading() / this.theta) * this.theta;
+ p.set(this.rootPos.add(toxi.Vec2D.fromTheta(heading).scaleSelf(delta.magnitude())));
+};/**
+ * Constrains a particle's movement by locking a given axis to a fixed value.
+ */
+toxi.physics2d.AxisConstraint = function(axis,constraintAmount){
+ this.axis = axis;
+ this.constraint = constraintAmount;
+};
+
+toxi.physics2d.AxisConstraint.prototype.applyConstraint = function(p){
+ p.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(p){
+ if(this.circle.containsPoint(p)){
+ p.set(this.circle.add(p.sub(this.circle).normalizeTo(this.circle.getRadius())));
+ }
+};toxi.physics2d.MaxConstraint = function(axis,threshold){
+ this.axis = axis;
+ this.threshold = threshold;
+};
+
+toxi.physics2d.MaxConstraint.prototype.applyConstraint = function(p){
+ if(p.getComponent(this.axis) > this.threshold){
+ p.setComponent(this.axis,this.threshold);
+ }
+};toxi.physics2d.MinConstraint = function(axis,threshold){
+ this.axis = axis;
+ this.threshold = threshold;
+};
+
+toxi.physics2d.MinConstraint.prototype.applyConstraint = function(p){
+ if(p.getComponent(this.axis) < this.threshold){
+ p.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(p){
+ if(this.rect.containsPoint(p)){
+ p.set(this.rect.intersectsRay(this.intersectRay.setDirection(this.intersectRay.sub(p)),0,Number.MAX_VALUE));
+ }
+ },
+
+ getBox: function(){
+ return this.rect.copy();
+ },
+
+ setBox: function(rect){
+ this.rect = rect.copy();
+ this.intersectRay.set(this.rect.getCentroid());
+ }
+};toxi.physics2d.ParticlePath2D = function(points){
+ toxi.Spline2D.call(this,points);
+ this.particles = [];
+};
+toxi.extend(toxi.physics2d.ParticlePath2D,toxi.Spline2D);
+
+(function(){
+ //protected
+ var createSingleParticle = function(pos,mass){
+ return new toxi.physics2d.VerletParticle2D(pos,mass);
+ };
+
+ //public
+ toxi.physics2d.ParticlePath2D.prototype.createParticles = function(physics,subDiv,step,mass){
+ this.particles = [];
+ this.computeVertices(subDiv);
+ var i = 0;
+ var dv = this.getDecimatedVertices(step,true);
+ for(i = 0; i < dv; i++){
+ var p = this.createSingleParticle(v,mass);
+ this.particles.push(p);
+ physics.addParticle(p);
+ }
+ return this.particles;
+ };
+
+
+})();/**
+* Utility builder/grouping/management class to connect a set of particles into
+* a physical string/thread. Custom spring types can be used by subclassing this
+* class and overwriting the
+* {@link #createSpring(VerletParticle2D, VerletParticle2D, float, float)}
+method.
+*/
+
+ /**
+ Construct a ParticleString2D,
+ parameter options:
+ 1 - options object
+ 3 - VerletPhysics2D physics, Array<VerletParticle2D> plist, Number strength
+ 6 - VerletPhysics2D physic, Vec2D pos, Vec2D step, Number num, Number mass, Number strength
+ */
+
+toxi.physics2d.ParticleString2D = function(){
+ var opts = {
+ physics: undefined,
+ plist: undefined,
+ pos: undefined,
+ step: undefined,
+ num: undefined,
+ mass: undefined,
+ strength: undefined
+ },
+ is6ParamConstructor = false;
+ if(arguments.length === 0){
+ throw new Error("Incorrect Parameters");
+ } else if(arguments.length == 1){ //options object
+ var arg = arguments[0];
+ for(var prop in arg){
+ opts[prop] = arg[prop];
+ }
+ } else {
+ opts.physics = arguments[0];
+ if(arguments.length == 6){
+ opts.pos = arguments[1];
+ opts.step = arguments[2];
+ opts.num = arguments[3];
+ opts.mass = arguments[4];
+ opts.strength = arguments[5];
+ } else {
+ opts.plist = arguments[1];
+ opts.strength = arguments[2];
+ }
+ }
+ if(opts.num !== undefined && opts.pos !== undefined && opts.step !== undefined && opts.mass !== undefined){
+ is6ParamConstructor = true;
+ }
+ if(!is6ParamConstructor && opts.plist === undefined){
+ throw new Error("Incorrect Parameters, please supply plist or num, pos, step & mass");
+ }
+
+
+ this.physics = opts.physics;
+ this.links = [];
+
+ var prev,
+ p,
+ s,
+ strength,
+ i = 0;
+
+
+ if(is6ParamConstructor){
+ var pos = opts.pos.copy(),
+ step = opts.step,
+ mass = opts.mass,
+ len = step.magnitude();
+ this.particles = [];
+ strength = opts.strength;
+
+ for(i = 0; i < opts.num; i++){
+ p = new toxi.physics2d.VerletParticle2D(pos.copy(),mass);
+ this.particles.push(p);
+ this.physics.particles.push(p);
+ if(prev !== undefined){
+ s = this.createSpring(prev,p,len,strength);
+ this.links.push(s);
+ this.physics.addSpring(s);
+ }
+ prev = p;
+ pos.addSelf(step);
+ }
+ } else {
+ strength = opts.strength;
+ this.particles = opts.plist || [];
+
+
+ for(i = 0; i < this.particles.length; i++){
+ p = this.particles[i];
+ this.physics.addParticle(p);
+ if(prev !== undefined){
+ s = this.createSpring(prev,p,prev.distanceTo(p),strength);
+ this.links.push(s);
+ this.physics.addSpring(s);
+ }
+ prev = p;
+ }
+ }
+ };
+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);
+ },
+
+ getHead: function(){
+ return this.particles[0];
+ },
+
+ getNumParticles: function(){
+ return this.particles.length;
+ },
+
+ getTail: function(){
+ return this.particles[this.particles.length-1];
+ }
+
+};/**
+* Creates a pullback spring (default restlength=0.5) between 2 particles and
+* locks the first one given at the current position. The spring is only
+* enforced if the current length of the spring exceeds the rest length. This
+* behaviour is the opposite to the {@link VerletMinDistanceSpring2D}.
+*/
+
+ toxi.physics2d.PullBackString2D = function(a,b,strength){
+ toxi.physics2d.VerletSpring2D.apply(this,[a,b,0,strength]);
+ a.lock();
+ this.setRestLength(0.5);
+ };
+ toxi.extend(toxi.physics2d.PullBackString2D,toxi.physics2d.VerletSpring2D);
+
+ toxi.physics2d.PullBackString2D.prototype.update = function(applyConstraints){
+ if(this.b.distanceToSquared(this.a) > this.restLengthSquared){
+ this.parent.update.call(this,applyConstraints);
+ }
+ };toxi.physics2d.VerletConstrainedSpring2D = function(particleA, particleB, len, str, limit){
+ toxi.physics2d.VerletSpring2D.call(this,particleA,particleB,len,str);
+ this.limit = (limit === undefined) ? Number.MAX_VALUE : limit;
+};
+
+toxi.extend(toxi.physics2d.VerletConstrainedSpring2D,toxi.physics2d.VerletSpring2D);
+
+
+toxi.physics2d.VerletConstrainedSpring2D.update = function(applyConstraints){
+ var delta = this.b.sub(this.a);
+ // add minute offset to avoid div-by-zero errors
+ var dist = delta.magnitude() + toxi.physics2d.VerletSpring2D.EPS;
+ var normDistStrength = (dist - this.restLength) / (dist * (this.a.invWeight + this.b.invWeight))* this.strength;
+ if (!this.a.isLocked && !this.isALocked) {
+ this.a.addSelf(delta.scale(normDistStrength * this.a.invWeight).limit(this.limit));
+ if (applyConstraints) {
+ this.a.applyConstraints();
+ }
+ }
+ if (!this.b.isLocked && !this.isBLocked) {
+ this.b.subSelf(delta.scale(normDistStrength * this.b.invWeight).limit(this.limit));
+ if (applyConstraints) {
+ this.b.applyConstraints();
+ }
+ }
+};toxi.physics2d.VerletMinDistanceSpring2D = function(particleA,particleB,len,str){
+ toxi.physics2d.VerletSpring2D.call(this,particleA,particleB,len,str);
+ this.setRestLength(len);
+};
+
+
+toxi.extend(toxi.physics2d.VerletMinDistanceSpring2D,toxi.physics2d.VerletSpring2D);
+
+toxi.physics2d.VerletMinDistanceSpring2D.prototype.update = function(applyConstraints){
+ if(this.b.distanceToSquared(this.a) < this.restLengthSquared){
+ this.parent.update.call(this,applyConstraints);
+ }
+};toxi.physics2d.VerletPhysics2D = function(gravity, numIterations, drag, timeStep){
+ this.behaviors = [];
+ this.particles = [];
+ this.springs = [];
+ this.numIterations = numIterations || 50;
+ this.timeStep = timeStep || 1;
+ this.setDrag(drag || 0);
+
+ if(gravity !== undefined){
+ this.addBehavior(new toxi.physics2d.GravityBehavior(gravity));
+ }
+};
+
+toxi.physics2d.VerletPhysics2D.addConstraintToAll = function(c, list){
+ for(var i=0;i<list.length;i++){
+ list[i].addConstraint(c);
+ }
+};
+
+toxi.physics2d.VerletPhysics2D.removeConstraintFromAll = function(c,list){
+ for(var i=0;i<list.length;i++){
+ list[i].removeConstraint(c);
+ }
+};
+
+toxi.physics2d.VerletPhysics2D.prototype = {
+
+ addBehavior: function(behavior){
+ behavior.configure(this.timeStep);
+ this.behaviors.push(behavior);
+ },
+
+ addParticle: function(p){
+ this.particles.push(p);
+ return this;
+ },
+
+ addSpring: function(s){
+ if(this.getSpring(s.a,s.b) === undefined){
+ this.springs.push(s);
+ }
+ return this;
+ },
+
+ clear: function(){
+ this.particles = [];
+ this.springs = [];
+ return this;
+ },
+
+ constrainToBounds: function(){ //protected
+ var p,
+ i = 0;
+ for(i=0;i<this.particles.length;i++){
+ p = this.particles[i];
+ if(p.bounds !== undefined){
+ p.constrain(p.bounds);
+ }
+ }
+ if(this.worldBounds !== undefined){
+ for(i=0;i<this.particles.length;i++){
+ p = this.particles[i];
+ p.constrain(this.worldBounds);
+ }
+ }
+ },
+
+ getCurrentBounds: function(){
+ var min = new toxi.Vec2D(Number.MAX_VALUE, Number.MAX_VALUE);
+ var max = new toxi.Vec2D(Number.MIN_VALUE, Number.MIN_VALUE);
+ var i = 0,
+ p;
+ for(i = 0;i<this.particles.length;i++){
+ p = this.particles[i];
+ min.minSelf(p);
+ max.maxSelf(p);
+ }
+ return new toxi.Rect(min,max);
+ },
+
+ getDrag: function() {
+ return 1 - this.drag;
+ },
+
+ getNumIterations: function(){
+ return this.numIterations;
+ },
+
+ getSpring: function(a,b){
+ var i = 0;
+ for(i = 0;i<this.springs.length;i++){
+ var s = this.springs[i];
+ if((s.a === a && s.b === b) || (s.a === b && s.b === b)){
+ return s;
+ }
+ }
+ return undefined;
+ },
+
+ getTimeStep: function(){
+ return this.timeStep;
+ },
+
+ getWorldBounds: function(){
+ return this.worldBounds;
+ },
+
+ removeBehavior: function(c){
+ return toxi.physics2d.removeItemFrom(c,this.behaviors);
+ },
+
+ removeParticle: function(p){
+ return toxi.physics2d.removeItemFrom(p,this.particles);
+ },
+
+ removeSpring: function(s) {
+ return toxi.physics2d.removeItemFrom(s,this.springs);
+ },
+
+ removeSpringElements: function(s){
+ if(this.removeSpring(s) !== undefined){
+ return (this.removeParticle(s.a) && this.removeParticle(s.b));
+ }
+ return false;
+ },
+
+ setDrag: function(drag){
+ this.drag = 1 - drag;
+ },
+
+ setNumIterations: function(numIterations){
+ this.numIterations = numIterations;
+ },
+
+ setTimeStep: function(timeStep){
+ this.timeStep = timeStep;
+ var i =0;
+ for(i = 0;i<this.behaviors.length;i++){
+ var b = this.behaviors[i];
+ b.configure(timeStep);
+ }
+ },
+
+ setWorldBounds: function(world){
+ this.worldBounds = world;
+ return this;
+ },
+
+ update: function(){
+ this.updateParticles();
+ this.updateSprings();
+ this.constrainToBounds();
+ return this;
+ },
+
+ updateParticles: function(){
+ var i = 0,
+ j = 0,
+ b,
+ p;
+ for(i = 0;i<this.behaviors.length;i++){
+ b = this.behaviors[i];
+ for(j = 0;j<this.particles.length;j++){
+ p = this.particles[j];
+ b.applyBehavior(p);
+ }
+ }
+ for(j = 0;j<this.particles.length;j++){
+ p = this.particles[j];
+ p.scaleVelocity(this.drag);
+ p.update();
+ }
+ },
+
+ updateSprings: function(){
+ var i = 0,
+ j = 0;
+ for(i = this.numIterations; i > 0; i--){
+ for(j = 0;j<this.springs.length;j++){
+ var s = this.springs[j];
+ s.update(i === 1);
+ }
+ }
+ }
+
+};
View
9,069 build/uncompressed/toxiclibs-debug.js
9,069 additions, 0 deletions not shown
View
1  examples/MeshAlignToAxis_webgl.html
@@ -8,7 +8,6 @@
<!-- Date: 2011-01-09 -->
<script type="text/javascript" src="js/webgl-utils.js"></script>
<script type="text/javascript" src="../build/toxiclibs.js"></script>
- <script type="text/javascript" src="../src/core/geom/mesh/TriangleMesh.js"></script>
</head>
<body class="container_12">
<header class="grid_12">
View
52