Hong Kong Generator

A Processing sketch for the generation of Hong Kong islands. Coded on the flight back from ISEA 2016.

hongkongmontage

// HONG KONG MOUNTAINSCAPES

Scene[] sceneGrid = new Scene[16];

void setup() {

size (1200, 800, P2D);

int xCount = 0;
int yCount = 0;

for (int i = 0; i < sceneGrid.length; i++) { sceneGrid[i] = new Scene(width*0.005 + width/4*xCount, height*0.005 + height/4*yCount, width*0.24, height*0.24); xCount++; if (xCount >= 4) {
xCount = 0;
yCount++;
}
}

// DRAW ONCE

background(100);
for (int i = 0; i < sceneGrid.length; i++) {
sceneGrid[i].drawScene();
}
}

void draw() {
}

void mouseClicked() {

// myScene = new Scene(random(width)*0.25, random(height)*0.25, random(width), random(height));
}

class Scene {

float x;
float y;
float w;
float h;
float seaLevel;
color seaC1, seaC2, seaC3, seaC4;
float mountainStart;
float mountainStop;
float mountainHeight;

Scene(float xIn, float yIn, float wIn, float hIn) {
x = xIn;
y = yIn;
w = wIn;
h = hIn;

// — SEA VARIABLES —
seaLevel = 0.25 + random(0.25);
seaC1 = color(100+random(50), 150+random(50), 200+random(25));
seaC2 = color(100+random(50), 150+random(50), 200+random(25));
seaC3 = color(100+random(50), 150+random(50), 200+random(25));
seaC4 = color(100+random(50), 150+random(50), 200+random(25));

// — MOUNTAIN VARIABLES —
mountainStart = random(w/4);
mountainStop = random(w/2) + w/2;
mountainHeight = random(h/2);
}

void drawScene() {

noStroke();
fill(200);

pushMatrix();

// move to start point
translate(x, y);

// first draw the background
rect(0, 0, w, h);

// now draw the sea
beginShape(QUADS);
fill(seaC1);
vertex(0, h-(h*seaLevel)-2);
fill(seaC2);
vertex(w, h-(h*seaLevel)-2);
fill(seaC3);
vertex(w, h);
fill(seaC4);
vertex(0, h);
endShape();

for (int n = 0; n < 10; n++) {

// now draw the mountain
float currentX = mountainStart;
float currentY = h-seaLevel*h;
boolean goUp = true;
beginShape();
noStroke();

vertex(mountainStart, h-seaLevel*h);

while (currentX < mountainStop) { fill(90+random(25), 150 + random(50), 120+random(25)); curveVertex(currentX, currentY); currentX += random(35) + 10; if (goUp) { currentY -= random(35); /* if (currentY > h-seaLevel*h) {
currentY = h-seaLevel*h;
}
*/
//currentY -= random(2);
if (currentY > mountainHeight) {
goUp = false;
}
} else {

currentY += random(25);

if (currentY > h-seaLevel*h) {
currentY = h-seaLevel*h;
}
}
}
vertex(mountainStop, h-seaLevel*h);
endShape();
}

// now draw skyscrapers

for (int n = 0; n < 20; n++) {
fill (random(100) + 90);
rect(50+mountainStart + random(50), h-seaLevel*h – random(5) – 2, random(5)+3, -random(15) – 10);
}

popMatrix();
}
}