title: Erasing previously drawn lines on an HTML5 canvas
body: <p>To play around with HTML5 canvas, I decided to make an app which draws an analogue clockface. Everything's fine, except that old lines don't get erased in the way that I would expect. I've included part of the code below - DrawHands() gets called once a second:</p>
  
  <pre><code>var hoursPoint = new Object();
  var minutesPoint = new Object();
  var secondsPoint = new Object();
  
  function drawHands()
  {
      var now = new Date();
  
      drawLine(centerX, centerY, secondsPoint.X, secondsPoint.Y, "white", 1);
      var seconds = now.getSeconds();
      secondsPoint = getOtherEndOfLine(centerX, centerY, 2 * Math.PI / 60 * seconds, 0.75 * radius);
      drawLine(centerX, centerY, secondsPoint.X, secondsPoint.Y, "black", 1);
  
      drawLine(centerX, centerY, minutesPoint.X, minutesPoint.Y, "white", 3);
      var minutes = now.getMinutes();
      minutesPoint = getOtherEndOfLine(centerX, centerY, 2 * Math.PI / 60 * minutes, 0.75 * radius);
      drawLine(centerX, centerY, minutesPoint.X, minutesPoint.Y, "black", 3);
  
      drawLine(centerX, centerY, hoursPoint.X, hoursPoint.Y, "white", 3);
      var hours = now.getHours();
      if (hours &gt;= 12) { hours -= 12; } // Hours are 0-11
      hoursPoint = getOtherEndOfLine(centerX, centerY, (2 * Math.PI / 12 * hours) + (2 * Math.PI / 12 / 60 * minutes), 0.6 * radius);
      drawLine(centerX, centerY, hoursPoint.X, hoursPoint.Y, "black", 3);
  }
  </code></pre>
  
  <p>To make sense of the above, there are two helper functions:</p>
  
  <ul>
  <li>drawLine(x1, y1, x2, y2, color, thickness)</li>
  <li>getOtherEndOfLine(x, y, angle, length)</li>
  </ul>
  
  <p>The problem is that while all the hands get drawn as expected in black, they never get erased. I would expect that since the same line is drawn in white (the background colour) it would effectively erase what was previously drawn at that point. But this doesn't seem to be the case.</p>
  
  <p>Anything I'm missing?</p>