Draws basic fractal (I forgot it's name). Click to draw next degree... Beware - if you go farer than 10 clicks or so it may kill your browser ;)
(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()
})();
KGZ1bmN0aW9uKCkgew0KICB2YXIgZSA9IGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCJjIiksDQogICAgICBjID0gZS5nZXRDb250ZXh0KCIyZCIpLA0KICAgICAgeCA9IHkgPSAwLjUsDQogICAgICBuID0gMCwgbCwNCiAgICAgIGNTaXplID0gNTAwOw0KDQogIGZ1bmN0aW9uIGxpbmUoZCkgew0KICAgIGMubGluZVRvKHggKz0gIWQgPyBsIDogZCA9PSAyID8gLWwgOiAwLCB5ICs9IGQgPT0gMSA/IGwgOiBkID09IDMgPyAtbCA6IDApDQogIH0NCg0KICBmdW5jdGlvbiBzdGVwKG4sIGYsIGMpIHsNCiAgICBpZihuID49IDApIHsNCiAgICAgIHZhciByID0gKGYgKyAoYyA/IDEgOiAzKSkgJSA0Ow0KICAgICAgc3RlcCgtLW4sIHIsICFjKTsNCiAgICAgIGxpbmUoZik7DQogICAgICBzdGVwKG4sIGYsIGMpOw0KICAgICAgbGluZShyKTsNCiAgICAgIHN0ZXAobiwgZiwgYyk7DQogICAgICBsaW5lKChmICsgMikgJSA0KTsNCiAgICAgIHN0ZXAobiwgKHIgKyAyKSAlIDQsICFjKTsNCiAgICB9DQogIH0NCiAgDQogIGZ1bmN0aW9uIHNpemUobikgew0KICAgIHJldHVybiBuID8gMiAqIHNpemUobiAtIDEpICsgMSA6IDENCiAgfQ0KDQogIGUuc3R5bGUuY3Vyc29yID0gInBvaW50ZXIiOw0KICBlLm9uY2xpY2sgPSBmdW5jdGlvbigpIHsNCiAgICBsID0gTWF0aC5tYXgoTWF0aC5jZWlsKGNTaXplIC8gc2l6ZShuKSksIDMpOw0KICAgIGNTaXplID0gc2l6ZShuKSAqIGw7DQogICAgZS53aWR0aCA9IGUuaGVpZ2h0ID0gY1NpemUgKyAxOw0KICAgIGMuY2xlYXJSZWN0KC0xLCAtMSwgY1NpemUgKyAxLCBjU2l6ZSArIDEpOw0KICAgIGMuYmVnaW5QYXRoKCk7DQogICAgYy5tb3ZlVG8oeCA9IDAuNSwgeSA9IDAuNSk7DQogICAgc3RlcChuKyssIDAsIDEpOw0KICAgIGMuc3Ryb2tlKCk7DQogIH07DQogIGUub25jbGljaygpDQoNCn0pKCk7
Original source not submitted