/** * Randomly generated color * @return Randomly generated hex color */function Randomcolor () {var colorstr=math.floor (Math.random () *0xffffff). ToString ( ). toUpperCase (); Return "#" + "000000". Substring (0,6-COLORSTR) +colorstr;}
/** * Hex color converted to RGB color * @param color to convert the hexadecimal color * @return RGB color */function colorhextorgb (color) {color=color.touppercase (); var Regexphex=/^#[0-9a-fa-f]{3,6}$/;//hex if (regexphex.test (color)) {var hexarray=new Array (); var count=1; for (Var i=1;i<=3;i++) {if (color.length-2*i>3-i) {Hexarray.push (number ("0x" +color.substring (count,count+2 ))); count+=2; }else{Hexarray.push (Number ("0x" +color.charat (count) +color.charat (count)); Count+=1; }} return "RGB (" +hexarray.join (",") + ")"; }else{return color; }}
/** * RGB color to hexadecimal color * @param color the RGB color to convert * @return hex Color * * Function Colorrgbtohex (color) {var regexprgb=/^ (rgb| RGB) ([0-9]{1,3},s?[ 0-9]{1,3},s? [0-9] {1,3}) $/;//rgb if (regexprgb.test (color)) {Color=color.replace (/((|) | rgb| RGB) */g, ""). Split (","); var colorhex= "#"; for (Var i=0;i<color.length;i++) {var hex=number (Color[i]). toString (16); if (hex.length==1) hex= "0" +hex; Colorhex+=hex; } return Colorhex; }else{return color; }}
JavaScript randomly generated colors and the conversion of hexadecimal colors to RGB color values