TDKHome.old/apps/color.html
MattTheTekie 98d6691f82 uwu
uwu
2023-07-14 10:46:07 -04:00

116 lines
No EOL
2.9 KiB
HTML

<html>
<head>
<title>Color Converter</title>
<meta name="viewport" content="width=240">
<script language="JavaScript">
function GiveDec(Hex)
{
if(Hex == "A")
Value = 10;
else
if(Hex == "B")
Value = 11;
else
if(Hex == "C")
Value = 12;
else
if(Hex == "D")
Value = 13;
else
if(Hex == "E")
Value = 14;
else
if(Hex == "F")
Value = 15;
else
Value = eval(Hex)
return Value;
}
function GiveHex(Dec)
{
if(Dec == 10)
Value = "A";
else
if(Dec == 11)
Value = "B";
else
if(Dec == 12)
Value = "C";
else
if(Dec == 13)
Value = "D";
else
if(Dec == 14)
Value = "E";
else
if(Dec == 15)
Value = "F";
else
Value = "" + Dec;
return Value;
}
function HexToRGB()
{
Input = window.document.forms['ColorForm'].elements['HexIn'].value;
Input = Input.toUpperCase();
a = GiveDec(Input.substring(0, 1));
b = GiveDec(Input.substring(1, 2));
c = GiveDec(Input.substring(2, 3));
d = GiveDec(Input.substring(3, 4));
e = GiveDec(Input.substring(4, 5));
f = GiveDec(Input.substring(5, 6));
x = (a * 16) + b;
y = (c * 16) + d;
z = (e * 16) + f;
window.document.forms['ColorForm'].elements['RedOut'].value = x;
window.document.forms['ColorForm'].elements['GreenOut'].value = y;
window.document.forms['ColorForm'].elements['BlueOut'].value = z;
}
function RGBToHex()
{
Red = window.document.forms['ColorForm'].elements['RedIn'].value;
Green = window.document.forms['ColorForm'].elements['GreenIn'].value;
Blue = window.document.forms['ColorForm'].elements['BlueIn'].value;
a = GiveHex(Math.floor(Red / 16));
b = GiveHex(Red % 16);
c = GiveHex(Math.floor(Green / 16));
d = GiveHex(Green % 16);
e = GiveHex(Math.floor(Blue / 16));
f = GiveHex(Blue % 16);
z = a + b + c + d + e + f;
window.document.forms['ColorForm'].elements['HexOut'].value = z;
}
function cleara(){
ColorForm.HexIn.value="";
ColorForm.HexOut.value="";
ColorForm.RedIn.value="";
ColorForm.RedOut.value="";
ColorForm.GreenIn.value="";
ColorForm.GreenOut.value="";
ColorForm.BlueIn.value="";
ColorForm.BlueOut.value="";
}
</script>
</head>
<body>
<center>
<form name="ColorForm">
HEX to RGB<br>
<input name="HexIn" maxlength="6" size="6" type="text">
<input value="Go" onclick="HexToRGB()" name="Button" type="button">
<input size="3" name="RedOut" maxlength="3" type="text"><input size="3" name="GreenOut" maxlength="3" type="text"><input size="3" name="BlueOut" maxlength="3" type="text">
<br><br>
RGB to HEX<br>
<input size="3" name="RedIn" maxlength="3" type="text"><input size="3" name="GreenIn" maxlength="3" type="text"><input size="3" name="BlueIn" maxlength="3" type="text">
<input value="Go" onclick="RGBToHex()" name="Button" type="button">
<input size="6" name="HexOut" maxlength="6" type="text"><br><br><input type="button" onclick="cleara();" value="Clear All">
</form>
</center>
</body>
</html>