Kwadraty wpisane w kwadrat
Listing
function kwadraty(ctx, nn, lg, xx, yy) { if(nn > 0){ ctx.moveTo(xx,yy); ctx.lineTo(xx + lg, yy); ctx.lineTo(xx + lg, yy + lg); ctx.lineTo(xx, yy + lg); ctx.lineTo(xx, yy + lg / 2); ctx.lineTo(xx + lg / 2, yy + lg); ctx.lineTo(xx + lg, yy + lg / 2); ctx.lineTo(xx + lg / 2, yy); ctx.lineTo(xx + lg / 4, yy + lg / 4); kwadraty(ctx, nn - 1, lg / 2, xx + lg / 4, yy + lg / 4); ctx.lineTo(xx, yy + lg / 2); ctx.lineTo(xx, yy); } } var cv = document.getElementById("canvas"); var ctx = cv.getContext("2d"); ctx.save(); ctx.beginPath() ctx.lineWidth=1; ctx.strokeStyle="blue"; kwadraty(ctx, 5, 400,10,10); ctx.stroke(); ctx.restore();