### City Generator

14Jan10

Images from processing sketch using fractals to draw city structures.

The code draws two identical cities, but positioned in reflection to one another: day changes to night, and the cities can be explored through interactions with the mouse.
In Italo Calvino’s novel Invisible Cities, he describes a city called Valdrada:
“The ancients built Valdrada on the shores of a lake, with houses all verandas one above the other, and high streets whose railed parapets look out over the water. Thus the traveler, arriving, sees two cities: one erect above the lake, and the other reflected, upside down. Nothing exists or happens in the one Valdrada that the other does not repeat, because the city was so constructed that its every point would be reflected in its mirror, and the Valdrada down in the water contains not only all the flutings and juttings of the facades that rise above the lake, but also the rooms’ interiors with ceilings and floors, perspective of the halls, the mirrors and the wardrobes.”

Here’s the code:
``` import processing.opengl.*; float cx, cy; float z = 0; void setup(){ size(800, 800, OPENGL); } void draw(){ background(0); float m = map(millis(), 0, 10000, 0, 1); if (keyPressed){ z+=5; }else{ z-=0.5; } z = constrain(z, 0, width/2); if (mousePressed){ float ccx = ((mouseX-(width/2))*0.003); float ccy = ((mouseY-(height/2))*0.003); cx = (cx*0.95)+(ccx*0.1); cy = (cy*0.95)+(ccy*0.1); } translate(width/2, height/2, z); rotateY(cx); rotateX(cy); directionalLight(255, 255, 255, sin(m), 0, cos(m)); fill(200, 200, 255); rect(-width/2, -height/2, width, height); street(70, 200, 8, HALF_PI); } void street(float s, float h, float g, float r){ s*=0.8; h*=0.9; if (s>g){ stroke(200, 200, 255); fill(200, 200, 255); pushMatrix(); rotateZ(r); box(g, g, h); translate(0, -s); street(s, h, g, r); popMatrix(); pushMatrix(); rotateZ(-r); box(g, h, g); translate(0, -s); street(s, h, g, r); popMatrix(); } }```