JS1K

#2: the original

Source for demo by bartaz.

(function() {
  var e = document.getElementById("c"),
      c = e.getContext("2d"),
      x = y = 0.5,
      n = 0, l,
      cSize = 500;

  function line(d) {
    c.lineTo(x += !d ? l : d == 2 ? -l : 0, y += d == 1 ? l : d == 3 ? -l : 0)
  }

  function step(n, f, c) {
    if(n >= 0) {
      var r = (f + (c ? 1 : 3)) % 4;
      step(--n, r, !c);
      line(f);
      step(n, f, c);
      line(r);
      step(n, f, c);
      line((f + 2) % 4);
      step(n, (r + 2) % 4, !c);
    }
  }
  
  function size(n) {
    return n ? 2 * size(n - 1) + 1 : 1
  }

  e.style.cursor = "pointer";
  e.onclick = function() {
    l = Math.max(Math.ceil(cSize / size(n)), 3);
    cSize = size(n) * l;
    e.width = e.height = cSize + 1;
    c.clearRect(-1, -1, cSize + 1, cSize + 1);
    c.beginPath();
    c.moveTo(x = 0.5, y = 0.5);
    step(n++, 0, 1);
    c.stroke();
  };
  e.onclick()

})();