Skip to content
Browse files

Merge pull request #7 from speednoisemovement/master

TColor.toHex bugfix
  • Loading branch information...
2 parents 24bd181 + 48d812b commit 431b80822012e94b581fb3f1499f401c13c7fede @hapticdata hapticdata committed May 21, 2011
Showing with 14 additions and 8 deletions.
  1. +1 −1 build/toxi-color.js
  2. +1 −1 build/toxiclibs.js
  3. +11 −5 src/color/TColor.js
  4. +1 −1 utils/build.py
View
2 build/toxi-color.js
@@ -14,7 +14,7 @@ toxi.MathUtils.clip(a,0,1);return this.setHSV(this.hsv)},setCMYK:function(a,b,d,
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=this.toARGB().toString(16);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: "+
+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(){for(var a="",b,d=0;d<3;d++){b=parseInt(this.rgb[d]*255).toString(16);a+=b.length==1?"0"+b:b}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};
View
2 build/toxiclibs.js
@@ -220,7 +220,7 @@ toxi.MathUtils.clip(e,0,1);return this.setHSV(this.hsv)},setCMYK:function(e,g,h,
setHSV:function(e,g,h){if(e instanceof Array){g=e[1];h=e[2];e=e[0]}e=[e,g,h];this.hsv[0]=e[0]%1;this.hsv[0]<0&&this.hsv[0]++;this.hsv[1]=toxi.MathUtils.clip(e[1],0,1);this.hsv[2]=toxi.MathUtils.clip(e[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(e){e%=1;e<0&&e++;this.hsv[0]=e;this.setHSV(this.hsv)},setMagenta:function(e){this.cmyk[1]=e;return this.setCMYK(this.cmyk)},
setRed:function(e){this.rgb[0]=e;return this.setRGB(this.rgb)},setRGB:function(e,g,h){if(e instanceof Array){g=e[1];h=e[2];e=e[0]}this.rgb[0]=toxi.MathUtils.clip(e,0,1);this.rgb[1]=toxi.MathUtils.clip(g,0,1);this.rgb[2]=toxi.MathUtils.clip(h,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(e){this.hsv[1]=toxi.MathUtils.clip(e,0,1);return this.setHSV(this.hsv)},
setYellow:function(e){this.cmyk[2]=e;return this.setCMYK(this.cmyk)},sub:function(e){return this.copy().subSelf(e)},subSelf:function(e){this.rgb[0]=toxi.MathUtils.max(this.rgb[0]-e.rgb[0],0);this.rgb[1]=toxi.MathUtils.max(this.rgb[1]-e.rgb[1],0);this.rgb[2]=toxi.MathUtils.max(this.rgb[2]-e.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(e){if(e===
-undefined)e=[];e[0]=this.cmyk[0];e[1]=this.cmyk[1];e[2]=this.cmyk[2];e[3]=this._alpha;return e},toHex:function(){var e=this.toARGB().toString(16);if(e.length>6)e=e.substring(2);return e},toHSVAArray:function(e){if(e===undefined)e=[];e[0]=this.hsv[0];e[1]=this.hsv[1];e[2]=this.hsv[2];e[3]=this._alpha;return e},toRGBAArray:function(e,g){if(e===undefined){e=[];g=0}e[g++]=this.rgb[0];e[g++]=this.rgb[1];e[g++]=this.rgb[2];e[g]=this._alpha;return e},toString:function(){return"toxi.color.TColor: rgb: "+
+undefined)e=[];e[0]=this.cmyk[0];e[1]=this.cmyk[1];e[2]=this.cmyk[2];e[3]=this._alpha;return e},toHex:function(){for(var e="",g,h=0;h<3;h++){g=parseInt(this.rgb[h]*255).toString(16);e+=g.length==1?"0"+g:g}return e},toHSVAArray:function(e){if(e===undefined)e=[];e[0]=this.hsv[0];e[1]=this.hsv[1];e[2]=this.hsv[2];e[3]=this._alpha;return e},toRGBAArray:function(e,g){if(e===undefined){e=[];g=0}e[g++]=this.rgb[0];e[g++]=this.rgb[1];e[g++]=this.rgb[2];e[g]=this._alpha;return e},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(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};
View
16 src/color/TColor.js
@@ -502,11 +502,17 @@ toxi.color.TColor.prototype = {
},
toHex: function() {
- var hex = this.toARGB().toString(16);
- if (hex.length > 6) {
- hex = hex.substring(2);
- }
- return hex;
+ var hexes = "",
+ d;
+ for (var i = 0; i < 3; i++) {
+ d = parseInt(this.rgb[i] * 255).toString(16);
+ if (d.length == 1) {
+ hexes += "0" + d;
+ } else {
+ hexes += d;
+ }
+ }
+ return hexes;
},
toHSVAArray: function(hsva) {
View
2 utils/build.py
@@ -178,7 +178,7 @@ def parse_args():
args = parser.parse_args()
else:
- parser = optparse.OptionParser(description='Build and compress Three.js')
+ parser = optparse.OptionParser(description='Build and compress toxiclibs.js')
parser.add_option('--includes', dest='includes', help='Build includes.js', action='store_true')
parser.add_option('--physics2d', dest='physics2d', help='Build toxi-physics2d.js', action='store_true')
parser.add_option('--core', dest='core', help='Build toxi-core.js', action='store_true')

0 comments on commit 431b808

Please sign in to comment.
Something went wrong with that request. Please try again.