From 3b6863c35eb55ff6587572a620d31e9349905956 Mon Sep 17 00:00:00 2001 From: hapticdata Date: Wed, 1 Jun 2011 12:14:33 -0500 Subject: [PATCH] bug fixes, TColor alpha made function --- build/toxi-color.js | 10 +++++----- build/toxi-core.js | 6 +++--- build/toxi-physics2d.js | 5 +++-- build/toxiclibs.js | 21 +++++++++++---------- src/color/TColor.js | 14 +++++++------- src/core/geom/Ellipse.js | 28 +++++++++++++--------------- src/physics/physics2d/physics2d.js | 1 + 7 files changed, 43 insertions(+), 42 deletions(-) diff --git a/build/toxi-color.js b/build/toxi-color.js index 5ca560e..07a5c89 100644 --- a/build/toxi-color.js +++ b/build/toxi-color.js @@ -2,9 +2,9 @@ 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+= -(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.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]-rgb[0],d=a.rgb[1]-rgb[1],c=a.rgb[2]-rgb[2];a=a.alpha-alpha;return Math.sqrt(b*b+d*d+c*c+a*a)=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; @@ -19,9 +19,9 @@ this.rgb[0]+", "+this.rgb[1]+", "+this.rgb[2]+" hsv: "+this.hsv[0]+","+this.hsv[ 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.alpha=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.alpha=b;return d};toxi.color.TColor.newHex=function(a){var b=new toxi.color.TColor;b.setRGB(toxi.color.TColor.hexToRGB(a));b.alpha=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.alpha=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.alpha=toxi.MathUtils.clip(c,0,1);return e}; +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(toxi.MathUtils.clip(a,0,1)*255).toString(16)+(toxi.MathUtils.clip(b,0,1)*255).toString(16)+(toxi.MathUtils.clip(d,0,1)*255).toString(16)}; 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, diff --git a/build/toxi-core.js b/build/toxi-core.js index 2cf792b..dda68ca 100644 --- a/build/toxi-core.js +++ b/build/toxi-core.js @@ -81,10 +81,10 @@ 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]+ (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;gthis.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;i0)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+this.width)return false;if(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)); diff --git a/build/toxi-physics2d.js b/build/toxi-physics2d.js index f7886d5..7be09af 100644 --- a/build/toxi-physics2d.js +++ b/build/toxi-physics2d.js @@ -1,6 +1,7 @@ // 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=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}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;athis.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;i0)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+this.width)return false;if(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)); @@ -208,9 +208,9 @@ toxi.Ray2D.prototype.getDirection=function(){return this.dir.copy()};toxi.Ray2D. 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]- +(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]- e.rgb[0]),Math.abs(this.rgb[1]-e.rgb[1]),Math.abs(this.rgb[2]-e.rgb[2]))},distanceToCMYK:function(e){var g=e.toCMYKAArray();e=this.cmyk[0]-g[0];var h=this.cmyk[1]-g[1],i=this.cmyk[2]-g[2];g=this.cmyk[3]-g[3];return Math.sqrt(e*e+h*h+i*i+g*g)},distanceToHSV:function(e){var g=this.hsv[0]*toxi.MathUtils.TWO_PI,h=e.hue()*toxi.MathUtils.TWO_PI;g=new toxi.Vec3D(Math.cos(g)*this.hsv[1],Math.sin(g)*this.hsv[1],this.hsv[2]);e=new toxi.Vec3D(Math.cos(h)*e.saturation(),Math.sin(h)*e.saturation(),e.brightness()); -return g.distanceTo(e)},distanceToRGB:function(e){var g=e.toRGBAArray();e=this.rgb[0]-g[0];var h=this.rgb[1]-g[1];g=this.rgb[2]-g[2];return Math.sqrt(e*e+h*h+g*g)},equals:function(e){if(e!==undefined&&e instanceof toxi.color.TColor){var g=e.rgb[0]-rgb[0],h=e.rgb[1]-rgb[1],i=e.rgb[2]-rgb[2];e=e.alpha-alpha;return Math.sqrt(g*g+h*h+i*i+e*e)=toxi.color.TColor.WHITE_POINT&&this.rgb[0]==this.rgb[1]&&this.rgb[0]==this.rgb[2]},lighten:function(e){this.hsv[2]=toxi.MathUtils.clip(this.hsv[2]+e,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(e){parseInt(toxi.MathUtils.degrees(e));var g=this.hsv[0]*360;e%=360; @@ -225,15 +225,16 @@ this.rgb[0]+", "+this.rgb[1]+", "+this.rgb[2]+" hsv: "+this.hsv[0]+","+this.hsv[ toxi.color.TColor.cmykToRGB=function(e,g,h,i,j){if(j===undefined)j=[0,0,0];j[0]=1-Math.min(1,e+i);j[1]=1-Math.min(1,g+i);j[2]=1-Math.min(1,h+i);return j};toxi.color.TColor.hexToRGB=function(e,g){if(g===undefined)g=[];e=e.charAt(0)=="#"?e.substring(1,7):e;g[0]=parseInt(e.substring(0,2),16)*toxi.color.TColor.INV8BIT;g[1]=parseInt(e.substring(2,4),16)*toxi.color.TColor.INV8BIT;g[2]=parseInt(e.substring(4,6),16)*toxi.color.TColor.INV8BIT;return g}; toxi.color.TColor.hsvToRGB=function(e,g,h,i){if(i===undefined)i=[];if(g==0)i[0]=i[1]=i[2]=h;else{e/=toxi.color.TColor.INV60DEGREES;var j=parseInt(e),k=e-j;e=h*(1-g);var n=h*(1-g*k);g=h*(1-g*(1-k));if(j==0){i[0]=h;i[1]=g;i[2]=e}else if(j==1){i[0]=n;i[1]=h;i[2]=e}else if(j==2){i[0]=e;i[1]=h;i[2]=g}else if(j==3){i[0]=e;i[1]=n;i[2]=h}else if(j==4){i[0]=g;i[1]=e;i[2]=h}else{i[0]=h;i[1]=e;i[2]=n}}return i}; toxi.color.TColor.labToRGB=function(e,g,h,i){if(i===undefined)i=[];e=(e+16)/116;g=g/500+e;h=e-h/200;i[0]=g;i[1]=e;i[2]=h;for(h=0;h<3;h++){e=Math.pow(i[h],3);i[h]=e>0.008856?e:(i[h]-16/116)/7.787}g=i[0]*0.95047;e=i[1];h=i[2]*1.08883;i[0]=g*3.2406+e*-1.5372+h*-0.4986;i[1]=g*-0.9689+e*1.8758+h*0.0415;i[2]=g*0.0557+e*-0.204+h*1.057;e=1/2.4;for(h=0;h<3;h++)i[h]=i[h]>0.0031308?1.055*Math.pow(i[h],e)-0.055:12.92*i[h];return i}; -toxi.color.TColor.newARGB=function(e){return toxi.color.TColor.newRGBA((e>>16&255)*toxi.color.TColor.INV8BIT,(e>>8&255)*toxi.color.TColor.INV8BIT,(e&255)*toxi.color.TColor.INV8BIT,(e>>>24)*toxi.color.TColor.INV8BIT)};toxi.color.TColor.newCMYK=function(e,g,h,i){return toxi.color.TColor.newCMYKA(e,g,h,i,1)};toxi.color.TColor.newCMYKA=function(e,g,h,i,j){var k=new TColor;k.setCMYK([e,g,h,i]);k.alpha=toxi.MathUtils.clip(j,0,1);return k}; -toxi.color.TColor.newGray=function(e){return toxi.color.TColor.newGrayAlpha(e,1)};toxi.color.TColor.newGrayAlpha=function(e,g){var h=new toxi.color.TColor;h.setRGB([e,e,e]);h.alpha=g;return h};toxi.color.TColor.newHex=function(e){var g=new toxi.color.TColor;g.setRGB(toxi.color.TColor.hexToRGB(e));g.alpha=1;return g};toxi.color.TColor.newHSV=function(e,g,h){return toxi.color.TColor.newHSVA(e,g,h,1)}; -toxi.color.TColor.newHSVA=function(e,g,h,i){var j=new toxi.color.TColor;j.setHSV(e,g,h);j.alpha=toxi.MathUtils.clip(i,0,1);return j};toxi.color.TColor.newRandom=function(){return toxi.color.TColor.newRGBA(Math.random(),Math.random(),Math.random(),1)};toxi.color.TColor.newRGB=function(e,g,h){return toxi.color.TColor.newRGBA(e,g,h,1)};toxi.color.TColor.newRGBA=function(e,g,h,i){var j=new toxi.color.TColor;j.setRGB([e,g,h]);j.alpha=toxi.MathUtils.clip(i,0,1);return j}; +toxi.color.TColor.newARGB=function(e){return toxi.color.TColor.newRGBA((e>>16&255)*toxi.color.TColor.INV8BIT,(e>>8&255)*toxi.color.TColor.INV8BIT,(e&255)*toxi.color.TColor.INV8BIT,(e>>>24)*toxi.color.TColor.INV8BIT)};toxi.color.TColor.newCMYK=function(e,g,h,i){return toxi.color.TColor.newCMYKA(e,g,h,i,1)};toxi.color.TColor.newCMYKA=function(e,g,h,i,j){var k=new TColor;k.setCMYK([e,g,h,i]);k.setAlpha(toxi.MathUtils.clip(j,0,1));return k}; +toxi.color.TColor.newGray=function(e){return toxi.color.TColor.newGrayAlpha(e,1)};toxi.color.TColor.newGrayAlpha=function(e,g){var h=new toxi.color.TColor;h.setRGB([e,e,e]);h.setAlpha(g);return h};toxi.color.TColor.newHex=function(e){var g=new toxi.color.TColor;g.setRGB(toxi.color.TColor.hexToRGB(e));g.setAlpha(1);return g};toxi.color.TColor.newHSV=function(e,g,h){return toxi.color.TColor.newHSVA(e,g,h,1)}; +toxi.color.TColor.newHSVA=function(e,g,h,i){var j=new toxi.color.TColor;j.setHSV(e,g,h);j.setAlpha(toxi.MathUtils.clip(i,0,1));return j};toxi.color.TColor.newRandom=function(){return toxi.color.TColor.newRGBA(Math.random(),Math.random(),Math.random(),1)};toxi.color.TColor.newRGB=function(e,g,h){return toxi.color.TColor.newRGBA(e,g,h,1)};toxi.color.TColor.newRGBA=function(e,g,h,i){var j=new toxi.color.TColor;j.setRGB([e,g,h]);j.setAlpha(toxi.MathUtils.clip(i,0,1));return j}; toxi.color.TColor.rgbToCMYK=function(e,g,h,i){if(i===undefined)i=[];i[0]=1-e;i[1]=1-g;i[2]=1-h;i[3]=toxi.MathUtils.min(i[0],i[1],i[2]);i[0]=toxi.MathUtils.clip(i[0]-i[3],0,1);i[1]=toxi.MathUtils.clip(i[1]-i[3],0,1);i[2]=toxi.MathUtils.clip(i[2]-i[3],0,1);i[3]=toxi.MathUtils.clip(i[3],0,1);return i};toxi.color.TColor.rgbToHex=function(e,g,h){return(toxi.MathUtils.clip(e,0,1)*255).toString(16)+(toxi.MathUtils.clip(g,0,1)*255).toString(16)+(toxi.MathUtils.clip(h,0,1)*255).toString(16)}; toxi.color.TColor.rgbToHSV=function(e,g,h,i){if(i===undefined)i=[];var j=0,k=0,n=toxi.MathUtils.max(e,g,h),m=n-toxi.MathUtils.min(e,g,h);if(n!=0)k=m/n;if(k!=0)j=e==n?(g-h)/m:g==n?2+(h-e)/m:4+(e-g)/m;j*=toxi.color.TColor.INV60DEGREES;if(j<0)j+=1;i[0]=j;i[1]=k;i[2]=n;return i};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); -toxi.physics2d=toxi.physics2d||{};toxi.physics2d.removeItemFrom=function(e,g){var h=g.indexOf(e);if(h>-1)return g.splice(h,1)};toxi.physics2d.VerletParticle2D=function(e,g,h){this.force=new toxi.Vec2D;if(e instanceof toxi.Vec2D)if(e instanceof toxi.physics2d.VerletParticle2D){g=e.y;h=e.weight;e=e.x;this.isLocked=e.isLocked}else{if(g===undefined){g=e.y;h=1}else{h=g;g=e.y}e=e.x}this.isLocked=false;this.init(e,g);this.prev=new toxi.Vec2D(this);this.temp=new toxi.Vec2D;h=h===undefined?1:h;this.setWeight(h)}; -toxi.extend(toxi.physics2d.VerletParticle2D,toxi.Vec2D);toxi.physics2d.VerletParticle2D.prototype.addBehavior=function(e,g){if(this.behaviors===undefined)this.behaviors=[];if(e===undefined)throw{name:"TypeError",message:"behavior was undefined"};g=g===undefined?1:g;e.configure(g);this.behaviors.push(e);return this};toxi.physics2d.VerletParticle2D.prototype.addConstraint=function(e){if(this.constraints===undefined)this.constraints=[];this.constraints.push(e);return this}; +toxi.physics2d=toxi.physics2d||{};toxi.physics2d.removeItemFrom=function(e,g){var h=g.indexOf(e);if(h>-1)return g.splice(h,1);console.log("undefined")}; +toxi.physics2d.VerletParticle2D=function(e,g,h){this.force=new toxi.Vec2D;if(e instanceof toxi.Vec2D)if(e instanceof toxi.physics2d.VerletParticle2D){g=e.y;h=e.weight;e=e.x;this.isLocked=e.isLocked}else{if(g===undefined){g=e.y;h=1}else{h=g;g=e.y}e=e.x}this.isLocked=false;this.init(e,g);this.prev=new toxi.Vec2D(this);this.temp=new toxi.Vec2D;h=h===undefined?1:h;this.setWeight(h)};toxi.extend(toxi.physics2d.VerletParticle2D,toxi.Vec2D); +toxi.physics2d.VerletParticle2D.prototype.addBehavior=function(e,g){if(this.behaviors===undefined)this.behaviors=[];if(e===undefined)throw{name:"TypeError",message:"behavior was undefined"};g=g===undefined?1:g;e.configure(g);this.behaviors.push(e);return this};toxi.physics2d.VerletParticle2D.prototype.addConstraint=function(e){if(this.constraints===undefined)this.constraints=[];this.constraints.push(e);return this}; toxi.physics2d.VerletParticle2D.prototype.addForce=function(e){this.force.addSelf(e);return this};toxi.physics2d.VerletParticle2D.prototype.addVelocity=function(e){this.prev.subSelf(e);return this};toxi.physics2d.VerletParticle2D.prototype.applyBehaviors=function(){if(this.behaviors!==undefined){var e=0;for(e=0;e -1){ return array.splice(index,1); } + console.log("undefined"); return undefined; }