// 鼠标经过高亮 var sys={} sys.setTF=function (mc:MovieClip, state:Boolean) { var ec:Number = state ? 32 : 0; var step:Number = state ? 8 : -8; var clr:Color = new Color(mc); var obj:Object = clr.getTransform(); mc.onEnterFrame = function() { obj.rb = obj.gb=obj.bb=obj.ab += step; if (state && obj.ab>ec || !state && obj.ab> i * 8 & 0xFF) - (n = (end >> i * 8 & 0xFF))) * Math.random() + n); for(var j = 2; j--;) rgb += h.charAt(rand >> j * 4 & 0xF); } this.setRGB(rgb); }; //usage cor = new Color(mc) cor.setRGBRandom("005500", "00FF00") // this will return value between 005500 and 00FF00 (00F500, 006D00,005F00,etc...) //ex: cor.setRGBRandom("55DD00", "66FF33"); cor.setRGBRandom("0000DD", "C24FF0"); cor.setRGBRandom("A0A0A0", "AFAFAF"); //etc... //-------------------------------------------------------------------------- // 虑镜 // photoshop fx : color dodge, linear dodge, linear burn, screen Color.prototype.colorDodge = function(r,g,b){ // correspond à: // calque avec rvb en mode colorDodge // par DESSUS l'image // CONFORME A PHOTOSHOP var trans = new Object(); trans.ra=100/((258-r)/256); trans.ga=100/((258-g)/256); trans.ba=100/((258-b)/256); this.setTransform(trans); } Color.prototype.linearDodge = function(r,g,b){ // correspond à: // calque rvb en mode linear Dodge // par dessus l'image // Conforme à PHOTOSHOP var trans = new Object(); trans.rb=r; trans.gb=g; trans.bb=b; this.setTransform(trans); } Color.prototype.linearBurn = function(r,g,b){ // correspond à : // calque avec rgb en mode linearBurn // par dessus la photo // Conforme à PHOTOSHOP var trans = new Object(); trans.rb=r-255; trans.gb=g-255; trans.bb=b-255; this.setTransform(trans); } Color.prototype.screen = function(r,g,b){ // correspond à : // image en mode screen // par dessus calque rvb // conforme à photoshop var trans = new Object(); trans.rb=r; trans.ra=100*(255-r)/255; trans.gb=g; trans.ga=100*(255-g)/255; trans.bb=b; trans.ba=100*(255-b)/255; this.setTransform(trans); } //usage couleur = new Color(_root.myMovieClip); couleur.colorDodge(150,200,250); //-------------------------------------------------------------------------- Color.prototype.HLStoRGB = function(h,l,s) { var r,g,b; if(s == 0) { r = g = b = Math.round(l/240*255); } else { h /= 240; l /= 240; s /= 240; var temp4,temp3; var temp2 = (l < 0.5) ? l*(s+1) : l+s-l*s; var temp1 = l*2 - temp2; for(var i=0; i<3; i++) { switch(i) { case 0: temp3 = h+1/3; break; case 1: temp3 = h; break; case 2: temp3 = h-1/3; break; } if(temp3 < 0) temp3++; else if(temp3 > 1) temp3--; if(temp3*6 < 1) temp4 = temp1+(temp2-temp1)*6*temp3; else if(temp3*2 < 1) temp4 = temp2; else if(temp3*3 < 2) temp4 = temp1+(temp2-temp1)*((2/3)-temp3)*6; else temp4 = temp1; switch(i) { case 0: r = Math.round(temp4*255); break; case 1: g = Math.round(temp4*255); break; case 2: b = Math.round(temp4*255); break; } } } return {r:r, g:g, b:b}; } // usage // You can compare these values to those produced in the Windows Color Picker (MS Paint, etc) h = 145; // scale from 0-240 l = 100; // same as above s = 120; // ditto myColor = new Color(); rgb = myColor.HLStoRGB(h,l,s); trace(rgb.r); trace(rgb.g); trace(rgb.b); //-------------------------------------------------------------------------- Color.prototype.HEXtoRGB = function(hex) { var rgb24 = (isNaN(hex)) ? parseInt(hex, 16) : hex; var r = rgb24 >> 16; var g = (rgb24 ^ (r << 16)) >> 8; var b = (rgb24 ^ (r << 16)) ^ (g << 8); return {r:r, g:g, b:b}; } // usage // A really basic script that anyone with the a bit of programming logistics could write // Still might be useful to someone who doesn't, though hex = 0xFF8796; //hex = "FF8796"; // will also work with strings myColor = new Color(); rgb = myColor.HEXtoRGB(hex); trace(rgb.r); trace(rgb.g); trace(rgb.b); //-------------------------------------------------------------------------- Color.prototype.RGBtoHEX = function(r,g,b) { r = r.toString(16); g = g.toString(16); b = b.toString(16); r = (r.length < 2) ? "0"+r : r; g = (g.length < 2) ? "0"+g : g; b = (b.length < 2) ? "0"+b : b; return (r+g+b).toUpperCase(); } //usage // A really basic script that anyone with the a bit of programming logistics could write // Still might be useful to someone who doesn't, though r = 255; g = 125; b = 75; myColor = new Color(); hex = myColor.RGBtoHEX(r,g,b); trace("#"+hex); //-------------------------------------------------------------------------- Color.prototype.HSBtoRGB = function(h,s,v) { var r,g,b; var h = Math.round(h); var s = Math.round(s*255/100); var v = Math.round(v*255/100); if(s == 0) { r = g = b = v; } else { var t1 = v; var t2 = (255-s)*v/255; var t3 = (t1-t2)*(h%60)/60; if(h==360) h = 0; if(h<60) {r=t1; b=t2; g=t2+t3} else if(h<120) {g=t1; b=t2; r=t1-t3} else if(h<180) {g=t1; r=t2; b=t2+t3} else if(h<240) {b=t1; r=t2; g=t1-t3} else if(h<300) {b=t1; g=t2; r=t2+t3} else if(h<360) {r=t1; g=t2; b=t1-t3} else {r=0; g=0; b=0} } return {r:r, g:g, b:b}; } //usage // This is another clensed Luzifer Altenberg script. He gets the most credit // You can compare these values to those produced in the Photoshop Color Picker h = 255; // 0<=h<=360 s = 100; // 0<=s<=100 b = 75; // 0<=b<=100 myColor = new Color(); rgb = myColor.HSBtoRGB(h,s,b); trace(rgb.r); trace(rgb.g); trace(rgb.b); //-------------------------------------------------------------------------- Color.prototype.RGBtoHSB = function(r,g,b) { var hsb = new Object(); hsb.b = Math.max(Math.max(r,g),b); var min = Math.min(Math.min(r,g),b); hsb.s = (hsb.b <= 0) ? 0 : Math.round(100*(hsb.b - min)/hsb.b); hsb.b = Math.round((hsb.b /255)*100); hsb.h = 0; if((r==g) && (g==b)) hsb.h = 0; else if(r>=g && g>=b) hsb.h = 60*(g-b)/(r-b); else if(g>=r && r>=b) hsb.h = 60 + 60*(g-r)/(g-b); else if(g>=b && b>=r) hsb.h = 120 + 60*(b-r)/(g-r); else if(b>=g && g>=r) hsb.h = 180 + 60*(b-g)/(b-r); else if(b>=r && r>=g) hsb.h = 240 + 60*(r-g)/(b-g); else if(r>=b && b>=g) hsb.h = 300 + 60*(r-b)/(r-g); else hsb.h = 0; hsb.h = Math.round(hsb.h); return hsb; } //usage // This is a cleaned up version of Luzifer Altenberg's script. He gets the most credit // You can compare these values to those produced in the Photoshop Color Picker r = 255; g = 50; b = 120; myColor = new Color(); hsb = myColor.RGBtoHSB(r,g,b); trace(hsb.h); // outputs a scale of 0-360 (degrees) trace(hsb.s); // outputs a scale of 0-100 (percent) trace(hsb.b); // same as above //-------------------------------------------------------------------------- Color.prototype.RGBtoHLS = function(r,g,b) { var h,l,s; var max = (Math.max(Math.max(r, g), b))/255; var min = (Math.min(Math.min(r, g), b))/255; var delta = max-min; l = (max+min)/2; s = (max == min) ? 0 : ((l <= 0.5) ? delta/l/2 : delta/(2-l*2)); if(r/255 == max) h = (g-b)/delta/255; else if(g/255 == max) h = 2+(b-r)/delta/255; else if(b/255 == max) h = 4+(r-g)/delta/255; h *= 40; if(h < 0) h += 240; h = Math.round(h); return {h:((isNaN(h)) ? 0 : h), l:Math.round(l*240), s:Math.round(s*240)}; } //usage // This was created with references to a few anonymous calculations written in other languages // None of which were very accurate // You can compare these values to those produced in the Windows Color Picker (MS Paint, etc) r = 145; g = 100; b = 120; myColor = new Color(); hls = myColor.RGBtoHLS(r,g,b); trace(hls.h); // outputs a scale of 0-240 trace(hls.l); // same as above trace(hls.s); // ditto