HTML Canvas simple example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<html>
<head>
 
<script type="text/javascript">
 
  function draw_rect(x,y) {
    var canvas = document.getElementById("m_canvas");
    if(canvas.getContext) {
      var ctx = canvas.getContext("2d");
      ctx.fillStyle = "rgb(200,0,0)";
      ctx.fillRect(x,y,5,5);
    }
  }
 
  function onMouseMove(evt) {
    draw_rect(evt.pageX,evt.pageY);
  }
 
  window.onmousemove = onMouseMove;
 
</script>
 
 
</head>
 
<canvas id="m_canvas" width="800" height="600">You need a better web browser.</canvas>
 
</body>
</html>

Leave a Reply