Any suggestions for improvement or critiques are welcome!
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="400" height="200" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
<input type="button" onclick="alert(ColorToText())" value="Click Here"/>
<script>
function TextToColor(arg){
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var text = arg;
var color;
var i;
for(i = 0;i<text.length;i++)
{
switch(text.charAt(i))
{
case "a":
color = "#000020";
break;
case "b":
color = "#000040";
break;
case "c":
color = "#000060";
break;
case "d":
color = "#000080";
break;
case "e":
color = "#0000a0";
break;
case "f":
color = "#0000c0";
break;
case "g":
color = "#0000e0";
break;
case "h":
color = "#001010";
break;
case "i":
color = "#002030";
break;
case "j":
color = "#003050";
break;
case "k":
color = "#004070";
break;
case "l":
color = "#005090";
break;
case "m":
color = "#0060b0";
break;
case "n":
color = "#0070d0";
break;
case "o":
color = "#0080f0";
break;
case "p":
color = "#009020";
break;
case "q":
color = "#00a040";
break;
case "r":
color = "#00b060";
break;
case "s":
color = "#00c080";
break;
case "t":
color = "#00d0a0";
break;
case "u":
color = "#00e0c0";
break;
case "v":
color = "#00f0e0";
break;
case "w":
color = "#102010";
break;
case "x":
color = "#204030";
break;
case "y":
color = "#306050";
break;
case "z":
color = "#408070";
break;
case " ":
color = "#50a090";
break;
case "-":
color = "#60c0b0";
break;
case "=":
color = "#70e0d0";
break;
case "0":
color = "#800000";
break;
case "1":
color = "#801000";
break;
case "2":
color = "#802000";
break;
case "3":
color = "#803000";
break;
case "4":
color = "#804000";
break;
case "5":
color = "#805000";
break;
case "6":
color = "#806000";
break;
case "7":
color = "#807000";
break;
case "8":
color = "#808000";
break;
case "9":
color = "#809000";
break;
default:
color = "#000000";
break;
};
ctx.fillStyle = color;
ctx.fillRect(i*1, 0, 1, 1);
};
}
function componentToHex(c) {
var hex = c.toString(16);
return hex.length == 1 ? "0" + hex : hex;
}
function rgbToHex(r, g, b) {
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}
function ColorToText()
{
var text = "";
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var imgData=ctx.getImageData(0,0,c.width,c.height);
for(var i = 0;i<imgData.data.length;i+=4)
{
var imgData=ctx.getImageData((i*1)/4,0,10,10);
red = imgData.data[0];
green = imgData.data[1];
blue = imgData.data[2];
var hex = rgbToHex(red, green, blue);
switch(hex)
{
case "#000020":
text+= "a";
break;
case "#000040":
text+= "b";
break;
case "#000060":
text+= "c";
break;
case "#000080":
text+= "d";
break;
case "#0000a0":
text+= "e";
break;
case "#0000c0":
text+= "f";
break;
case "#0000e0":
text+= "g";
break;
case "#001010":
text+= "h";
break;
case "#002030":
text+= "i";
break;
case "#003050":
text+= "j";
break;
case "#004070":
text+= "k";
break;
case "#005090":
text+= "l";
break;
case "#0060b0":
text+= "m";
break;
case "#0070d0":
text+= "n";
break;
case "#0080f0":
text+= "o";
break;
case "#009020":
text+= "p";
break;
case "#00a040":
text+= "q";
break;
case "#00b060":
text+= "r";
break;
case "#00c080":
text+= "s";
break;
case "#00d0a0":
text+= "t";
break;
case "#00e0c0":
text+= "u";
break;
case "#00f0e0":
text+= "v";
break;
case "#102010":
text+= "w";
break;
case "#204030":
text+= "x";
break;
case "#306050":
text+= "y";
break;
case "#408070":
text+= "z";
break;
case "#50a090":
text+= " ";
break;
case "#60c0b0":
text+= "-";
break;
case "#70e0d0":
text+= "=";
break;
case "#800000":
text+= "0";
break;
case "#801000":
text+= "1";
break;
case "#802000":
text+= "2";
break;
case "#803000":
text+= "3";
break;
case "#804000":
text+= "4";
break;
case "#805000":
text+= "5";
break;
case "#806000":
text+= "6";
break;
case "#807000":
text+= "7";
break;
case "#808000":
text+= "8";
break;
case "#809000":
text+= "9";
break;
};
};
return text;
}
TextToColor(("0663089000004 EVO-RC EVOLUTION CANDLE REMOTE 00663089005009").toLowerCase());
</script>
</body>
</html>