- <html>
- <head>
- <script>
-
- var mirc= [
- "FFFFFF", "000000",
- "7F0000", "007F00",
- "0000FF", "00007F",
- "7F007F", "007FFF",
- "00FFFF", "00FF00",
- "808040", "FFFF00",
- "FF0000", "FF00FF",
- "5C5C5C", "B8B8B8"
- ];
-
- function update()
- {
- newwin = window.open('','test','width=400,height=200,toolbar=no,status=no,menubar=no,location=no,scrollbars=no,resizable=no')
- newwin.document.write("<font color='#"+document.form1.color.value+"' size=+2><b>Couleur HTML "+document.form1.color.value+"</b></font>");
- newcolor = irccolor(document.form1.color.value);
- newcolorHex = mirc[newcolor];
- newwin.document.write("<br><font color='#"+newcolorHex+"' size=+2><b>Couleur MIRC "+newcolor+"</b></font>");
- }
-
- function irccolor(hexcolor)
- {
- var red = 0
- var green = 0
- var blue = 0
-
- red = parseInt(hexcolor.substr(0,2),16);
- green = parseInt(hexcolor.substr(2,2),16);
- blue = parseInt(hexcolor.substr(4,2),16);
-
- var bestmirccoul = -1;
- var bestdistance = 0;
-
- for (var i = 0; i<16; i++)
- {
- distance = Math.pow(red - parseInt(mirc[i].substr(0,2),16), 2) + Math.pow(green - parseInt(mirc[i].substr(2,2),16), 2) + Math.pow(blue - parseInt(mirc[i].substr(4,2),16), 2);
- distance = Math.pow(distance, 0.5);
- if (bestmirccoul < 0 || distance < bestdistance)
- {
- bestdistance = distance;
- bestmirccoul = i;
- }
- }
-
- alert("La couleur la plus proche de "+hexcolor+" est la couleur mirc "+bestmirccoul+" de distance "+distance);
- return bestmirccoul;
-
- }
- </script>
- </head>
-
- <body>
- <form name="form1">
- <input type="text" name="color" onchange="update();">
- <hr>
- </form>
- </body>
- </html>
<html>
<head>
<script>
var mirc= [
"FFFFFF", "000000",
"7F0000", "007F00",
"0000FF", "00007F",
"7F007F", "007FFF",
"00FFFF", "00FF00",
"808040", "FFFF00",
"FF0000", "FF00FF",
"5C5C5C", "B8B8B8"
];
function update()
{
newwin = window.open('','test','width=400,height=200,toolbar=no,status=no,menubar=no,location=no,scrollbars=no,resizable=no')
newwin.document.write("<font color='#"+document.form1.color.value+"' size=+2><b>Couleur HTML "+document.form1.color.value+"</b></font>");
newcolor = irccolor(document.form1.color.value);
newcolorHex = mirc[newcolor];
newwin.document.write("<br><font color='#"+newcolorHex+"' size=+2><b>Couleur MIRC "+newcolor+"</b></font>");
}
function irccolor(hexcolor)
{
var red = 0
var green = 0
var blue = 0
red = parseInt(hexcolor.substr(0,2),16);
green = parseInt(hexcolor.substr(2,2),16);
blue = parseInt(hexcolor.substr(4,2),16);
var bestmirccoul = -1;
var bestdistance = 0;
for (var i = 0; i<16; i++)
{
distance = Math.pow(red - parseInt(mirc[i].substr(0,2),16), 2) + Math.pow(green - parseInt(mirc[i].substr(2,2),16), 2) + Math.pow(blue - parseInt(mirc[i].substr(4,2),16), 2);
distance = Math.pow(distance, 0.5);
if (bestmirccoul < 0 || distance < bestdistance)
{
bestdistance = distance;
bestmirccoul = i;
}
}
alert("La couleur la plus proche de "+hexcolor+" est la couleur mirc "+bestmirccoul+" de distance "+distance);
return bestmirccoul;
}
</script>
</head>
<body>
<form name="form1">
<input type="text" name="color" onchange="update();">
<hr>
</form>
</body>
</html>