|
No idea how well this works but it looked to blend correctly. I am hoping not to get killed for posting this. XD function blendColors(){ var hexconv = new Array(); hexconv[0] = ["FF","1"]; hexconv[1] = ["CC","2"]; hexconv[2] = ["99","3"]; hexconv[3] = ["66","4"]; hexconv[4] = ["33","5"]; hexconv[5] = ["00","6"]; var hexnums = new Array(); var inchash = false; if(arguments.length < 2){ var error = new Error(); error.message = "Invalid ammount of parameters."; throw error; return false; } for(a=0;a<arguments.length;a++){ if(!arguments[a].match(/^(#)?\w{6}$/i)){ var error = new Error(); error.message = "Error in parsing hex value."; throw error; return false; }} for(a=0;a<arguments.length;a++){ var toaddhex = ''; if(arguments[a].match(/^#/i)){ inchash = true; var hexcolor = arguments[a].split(/^#/i)[1]; } else { var hexcolor = arguments[a]; } for(h=0;h<3;h++){ if(hexcolor.match(/^(\w{2})/i)){ var twohex = RegExp.$1; hexcolor = hexcolor.replace(/^\w{2}/i,''); if(twohex.match(/^(FF|CC|99|66|33|00)$/i)){ for(k=0;k<hexconv.length;k++){ if(twohex.match(new RegExp('^'+hexconv[k][0]+'$','i'))){ toaddhex += hexconv[k][1]; break; }}} else { var error = new Error(); error.message = "Error in parsing hex value."; throw error; return false; }}} hexnums.push(toaddhex); } var hexpnum = 0; var fhdigit = 0; var shdigit = 0; var thdigit = 0; for(g=0;g<hexnums.length;g++){ var fsdig = hexnums[g].charAt(0); fhdigit += parseInt(fsdig); var ssdig = hexnums[g].charAt(1); shdigit += parseInt(ssdig); var tsdig = hexnums[g].charAt(2); thdigit += parseInt(tsdig); } fhdigit = Math.round(fhdigit / hexnums.length); fhdigit = fhdigit.toString(); shdigit = Math.round(shdigit / hexnums.length); shdigit = shdigit.toString(); thdigit = Math.round(thdigit / hexnums.length); hexpnum = fhdigit+shdigit+thdigit; var finhex = ''; for(j=0;j<3;j++){ if(hexpnum.match(/^(\d{1})/)){ var twohex = RegExp.$1; hexpnum = hexpnum.replace(/^\d{1}/,''); for(q=0;q<hexconv.length;q++){ if(twohex.match(new RegExp('^'+hexconv[q][1]+'$','i'))){ finhex += hexconv[q][0]; break; }}}} if(inchash){ finhex = '#'+finhex; } return finhex; } Used like this: blendColors("hex color1,"hex color2"); You may blend more than two hex colors.  Hopefully it works alright.
|
Greg says: Coding music... Greg says: Hmm... Greg says: I wouldn't rule it out. Chris 3.0 [New features? Yes.] says:
 Greg says: If you think about machine code it's a bunch of 1s and 0s Chris 3.0 [New features? Yes.] says: Anything is possible. Greg says: Yeah try to code Metallica Chris 3.0 [New features? Yes.] says:
Yeah, I'll get right on that... right after I learn to fly.
|
|
|
|
Wow... Good job Greg.
|
|
|
|