So I have this code that I’m doing for a lab, thankfully my Comp-Sci teacher gave me some extra time. However, I’m confused about how the code won’t seem to work. It all makes sense to me, so maybe an eye from someone who could code better could help. The lab requires 12 buildings, all 50 in length, and they need randomized heights. With a click of a mouse, the buildings should change in heights, and the lights should change. I have the lights and the 200 random stars on lockdown, so it’s all good there. Here’s my code:
int [] buildingY = new int [12];
int [] starX = new int [200];
int [] starY = new int [200];
int i = 0;
int x = i*50;
int y = height-buildingY[i]*50;
void setup()
{
size(600,450);
rectMode(CORNER);
ellipseMode(CORNER);
drawAll();
randomize();
}
void draw()
{
}
void drawAll()
{
drawSky();
drawBuildings();
}
// this is used to randomize the 200 stars and the size of the building.
void randomize()
{
for(i=0; i<12; i++);
{
buildingY[i] = (int)random(1,8);
}
for(i=0; i<200; i++)
{
starX[i] = (int) random(0,width);
starY[i] = (int) random(0,height);
}
}
// this draws the sky and the randomized stars
void drawSky()
{
background(0);
stroke(255);
strokeWeight(1);
for(i=0; i<200; i++)
{
starX[i] = (int) random(0,width);
starY[i] = (int) random(0,height);
point(starX[i],starY[i]);
}
fill(255);
ellipse(500,-50,150,150);
}
// this calls upon the building parameters method, to draw the buildings 12 times.
void drawBuildings()
{
for(i=0; i<12; i++)
{
drawBuildingParams();
}
}
// used to draw the buildings and the windows.
void drawBuildingParams()
{
fill(100);
stroke(0);
rect(x,y,50,height-y);
for(int col = x+5; col<x+45; col+=9)
{
for(int row = y+10; row<height; row+=25)
{
if((int)random(2)==0)
fill(200,200,0);
else
fill(0);
rect(col,row,5,12);
}
}
}
// this randomizes the stars, height of the buildings, and the windows being yellow or black with a click.
void mousePressed()
{
randomize();
drawAll();
}
Thanks,
-Jonathan