Processing source code that was used to generate the little cityscapes for my Ben Folds Five poster.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ben Folds Five Poster - Cityscape Generator by Brendan Dawes | |
// http://brendandawes.com/projects/benfoldsfive/ | |
// Requires library from http://toxiclibs.org | |
import toxi.color.*; | |
import toxi.util.datatypes.*; | |
import processing.pdf.*; | |
final color BACKGROUND_COLOR = color(240); | |
final int NUMBER_OF_COLORS = 2; | |
final int NUMBER_OF_CITIES = 10; | |
final int BUILDING_HEIGHT = 120; | |
int xStep = 175; | |
int yStep = 200; | |
int cols = 3; | |
int totalWidth = xStep*cols; | |
float noiseCounter; | |
ColorList palette = new ColorList(); | |
int m = millis(); | |
void setup() { | |
size(648,864); | |
background(BACKGROUND_COLOR); | |
noStroke(); | |
noLoop(); | |
noiseDetail(8,0.5); | |
palette = getColorPalette(); | |
beginRecord(PDF, m+"benfolds-####.pdf"); | |
} | |
void draw() { | |
float xCenterOffset = ((width-totalWidth+xStep/2)/2); | |
for (int i=0; i < NUMBER_OF_CITIES; i++) { | |
float x = floor((i*xStep)%totalWidth); | |
float y = floor((i*xStep)/totalWidth)*yStep; | |
pushMatrix(); | |
translate(x+xCenterOffset,y+100); | |
noStroke(); | |
makeCity(); | |
popMatrix(); | |
} | |
endRecord(); | |
saveFrame(m+"benfolds-####.tif"); | |
} | |
ColorList getColorPalette() { | |
ColorTheme theme = new ColorTheme("theme"); | |
theme.addRange("soft teal",0.5); | |
theme.addRange("soft ivory",0.1); | |
ColorList l = theme.getColors(NUMBER_OF_COLORS); | |
return l; | |
} | |
boolean isMinorKey(int i){ | |
if (i == 1 || i == 3 || i == 6 || i == 8 || i == 10) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
void drawMinorKey(float x, float y) { | |
fill(0); | |
float w = max(9,random(20)); | |
float h = max(3,random(30)); | |
rect(x,y,w,-h); | |
} | |
void drawMajorKey(float x, float y){ | |
color c = palette.get(int(random(palette.size()))).toARGB(); | |
fill(c); | |
float w = max(8,random(20)); | |
float n = noise(noiseCounter); | |
float h = n*BUILDING_HEIGHT; | |
rect(x,y,w,-h); | |
for (int j=0; j < random(5); j++) { | |
float winY = (h/2)+random(h/2); | |
float winX = 2+random(w-4); | |
fill(BACKGROUND_COLOR); | |
rect(x+winX,y-winY,random(3),random(3)); | |
noiseCounter += 0.5; | |
} | |
} | |
void makeCity() { | |
float x; | |
float y; | |
noiseCounter = random(1000); | |
for (int i=0; i < 12; i++) { | |
x = (9*i); | |
y = 0; | |
if (isMinorKey(i)) { | |
drawMinorKey(x,y); | |
} else { | |
drawMajorKey(x,y); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment