vendredi 4 novembre 2016

Random 2D Cityscape generator, how do I randomly generate?

I have to randomly generate a cityscape with 3 layered functions in processing. I'm doing so by drawing each floor in a loop that runs until a random integer, and doing the same thing with floors per building. Currently, the floors are initially randomly generated, but then they eventually fill out to the maximum of the random function. How do I get it so they stay random? Thanks, code is below.

int boxX = 0;
int boxY = 479;
void setup() {
  size(1000, 500);
  background(255); 
  frameRate(10);
}

void draw() {
  for (int i = 0; i < 8; i++) {
    building(boxX, boxY);
    translate(150, 0);
  }
}
void room(int boxX, int boxY) {
  rect(boxX, boxY, 20, 20);
}

void floor(int boxX, int boxY) {
  int randomNum = (int)random(3, 5);
  for (int i=0; i<= randomNum; i++) {
    room(boxX, boxY);
    boxX += 20;
  }
}

void building(int boxX, int boxY) {
  int randomNum = int(random(10, 20));
  for (int i = 0; i < randomNum; i++) {
    floor(boxX, boxY);
    boxY -= 20;
  }
}




Aucun commentaire:

Enregistrer un commentaire