### Generating a random office building

I'm trying to write a program that generates a randomized city scene (with respect to the color/height/width/placement of the buildings in it) and am currently focusing on generating one office building with random height, width, color, and number of windows.

I'm having a spot of trouble figuring out how to constrain my number of rows/columns of windows to fit nicely within the office building. This seems like some relatively simple math that I'm just not wrapping my head around, but if there's a cleaner way to do this programming-wise I'd welcome suggestions about that as well.

Here's my code so far:
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243`` ``````#include "library.h" void one_window(int x, int y, int width, int height) { fill_rectangle(x,y,width,height); } void row_windows(int x, int y, int width, int height, int n) { one_window(x,y,width,height); if(n>1) { row_windows(x+(1.5*width),y,width,height,n-1); } } void block_windows(int x, int y, int width, int height, int n, int floors) { row_windows(x,y,width,height,n); if(floors>1) { block_windows(x,y+(1.5*height),width,height,n,floors-1); } } void office_building(int x, int y, int width, int height, int n, int floors) { double R = (random_in_range(0,30))/100.0; double G = (random_in_range(0,30))/100.0; double B = (random_in_range(0,30))/100.0; set_pen_color(R,G,B); fill_rectangle(x,y,width,height); double Gw = (random_in_range(10,25))/100.0; double Bw = (random_in_range(10,25))/100.0; set_pen_color(0,Gw,Bw); block_windows(x+(n),y+(floors),((width/n)-n),((height/floors)-floors),n,floors); } void main() { int width = random_in_range(100,300); int height = random_in_range(100,300); int n = random_in_range(4,6); int floors = random_in_range(5,20); make_window(600,600); office_building(100,200,width,height,n,floors); }``````

Thanks!
Topic archived. No new replies allowed.