<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="700" height="600"
style="border:1px solid #d3d3d3;">
</canvas>
<script>
var n = 10, m = 20;
var state = [];
for (var i = 0; i <= m; i++){
state[i] = [];
for (var j = 0; j <= n; j++){
state[i][j] = 0;
}
}
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.font = "30px Arial";
setInterval(function () {
var ind1 = Math.floor(Math.random() * 20)+1;
var ind2 = Math.floor(Math.random() * 10)+1;
ctx.clearRect(0,0,700,600);
state[ind1-1][ind2-1] = 1;
for (var index1 = 0; index1 < 20;index1++){
for (var index2 = 0; index2 < 10;index2++){
if (state[index1][index2] == 0){
ctx.fillStyle = "black";
ctx.fillText("9",index1*25,index2*35);
}
if (state[index1][index2] == 1){
ctx.fillStyle = "red";
ctx.fillText("9",index1*25,index2*35);
}
}
}
},1);
</script>
</body>
</html>
|