User:Joak/canvas1: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
<canvas id="c1" showsrc> | <canvas id="c1" showsrc> | ||
function unit () { | |||
// a single housing unit | |||
ctx.strokeRect(0, 0, 10, 10); | |||
} | |||
function street () { | |||
// a linear row of houses | |||
ctx.save(); | |||
var numhouses = Math.floor(Math.random()*15); | |||
for (c=0; c<numhouses; c++) { | |||
unit(); | |||
ctx.translate(10, 0); | |||
} | |||
ctx.restore(); | |||
} | |||
function city (l) { | |||
// rows of streets | |||
for (x=0; x<12; x++) { | |||
street(); | |||
ctx.translate(0, 20); | |||
} | |||
} | |||
function draw() { | function draw() { | ||
c = document.getElementById("c1"); | |||
ctx = c.getContext('2d'); | |||
city(); | |||
} | } | ||
</canvas> | </canvas> |
Revision as of 12:18, 1 October 2012
<canvas id="c1" showsrc> function unit () {
// a single housing unit ctx.strokeRect(0, 0, 10, 10);
}
function street () {
// a linear row of houses ctx.save(); var numhouses = Math.floor(Math.random()*15); for (c=0; c<numhouses; c++) { unit(); ctx.translate(10, 0); } ctx.restore();
}
function city (l) {
// rows of streets for (x=0; x<12; x++) { street(); ctx.translate(0, 20); }
}
function draw() {
c = document.getElementById("c1"); ctx = c.getContext('2d'); city();
}
</canvas>