- Impact
- 0
I made this last year when I was bored, it is a simple javascript where you press a button and a random hex color shows up in the box, along with its number.
It is here online: http://www.therustybarrel.com/david/experiments/randhex.html
But here's the main code:
<script language="Javascript">
<!--
function genHex(){
colors = new Array(14)
colors[0]="0"
colors[1]="1"
colors[2]="2"
colors[3]="3"
colors[4]="4"
colors[5]="5"
colors[5]="6"
colors[6]="7"
colors[7]="8"
colors[8]="9"
colors[9]="a"
colors[10]="b"
colors[11]="c"
colors[12]="d"
colors[13]="e"
colors[14]="f"
digit = new Array(5)
color=""
for (i=0;i<6;i++){
digit=colors[Math.round(Math.random()*14)]
color = color+digit
}
document.getElementById('hexc').style.backgroundColor=color
document.getElementById('hexn').innerText="#"+color
}
//-->
</script>
<table>
<tr>
<td id="hexc" height="100" width="100"> </td><td id="hexn"></td>
</tr>
</table>
<form>
<input type="button" onClick="genHex();"value="Generate Random Color">
</form>
enjoy ^_^
It is here online: http://www.therustybarrel.com/david/experiments/randhex.html
But here's the main code:
<script language="Javascript">
<!--
function genHex(){
colors = new Array(14)
colors[0]="0"
colors[1]="1"
colors[2]="2"
colors[3]="3"
colors[4]="4"
colors[5]="5"
colors[5]="6"
colors[6]="7"
colors[7]="8"
colors[8]="9"
colors[9]="a"
colors[10]="b"
colors[11]="c"
colors[12]="d"
colors[13]="e"
colors[14]="f"
digit = new Array(5)
color=""
for (i=0;i<6;i++){
digit=colors[Math.round(Math.random()*14)]
color = color+digit
}
document.getElementById('hexc').style.backgroundColor=color
document.getElementById('hexn').innerText="#"+color
}
//-->
</script>
<table>
<tr>
<td id="hexc" height="100" width="100"> </td><td id="hexn"></td>
</tr>
</table>
<form>
<input type="button" onClick="genHex();"value="Generate Random Color">
</form>
enjoy ^_^