City Generator


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(){
float m = map(millis(), 0, 10000, 0, 1);
if (keyPressed){
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);
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){
if (s>g){
stroke(200, 200, 255);
fill(200, 200, 255);
box(g, g, h);
translate(0, -s);
street(s, h, g, r);
box(g, h, g);
translate(0, -s);
street(s, h, g, r);


No Responses Yet to “City Generator”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: