User:Nan Wang/counting

From XPUB & Lens-Based wiki
< User:Nan Wang
Revision as of 17:34, 18 October 2012 by Nan Wang (talk | contribs)

function unit () {

 // a single housing unit
 ctx.beginPath();
 ctx.arc(5, 5, 5, 0, Math.PI, false);
 ctx.closePath();
 ctx.stroke();
 // ctx.strokeRect(0, 0, 10, 10);

}

function street () {

 // a linear row of houses
 ctx.save();
 for (c=0; c<10; c++) {
   unit();
   ctx.translate(10, 0);
 }
 ctx.restore();

}

function street (r) {

 // a curved row of houses
 var length = Math.PI * r,
   numunits = length/10,
   step = length/numunits,
   turn = Math.PI/(numunits-1);

 ctx.save();
 ctx.translate(-r, 0);
 ctx.rotate(-Math.PI/2);
 for (c=0; c<numunits; c++) {
   unit();
   ctx.translate(step, 0);
   ctx.rotate(turn);
 }
 ctx.restore();

}

function city (l) {

 // rows of streets
 ctx.translate(125, 125);
 for (var r=30; r<120; r+=20) {
   street(r);
 }

}

var c, ctx; function draw() {

 c = document.getElementById("c3");
 ctx = c.getContext("2d");
 city();

}

ccc_900.jpg nan_900.jpg

http://www.openprocessing.org/sketch/73805/check