HTML Canvas simple example

<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

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>