Question & Answer: Create an array for these rectangles in processing. int rec = 50; void setup()…..

Create an array for these rectangles in processing.

int rec = 50;

void setup()
{
size( 810, 810 );

}

void draw()
{

fill(150);
rect(380, 200, rec, rec);
rect(290, 110, rec, rec);
rect(200, 110, rec, rec);
rect(470, 110, rec, rec);
rect(560, 110, rec, rec);
rect(650, 200, rec, rec);
rect(650, 290, rec, rec);
rect(650, 380, rec, rec);
rect(560, 470, rec, rec);
rect(470, 560, rec, rec);
rect(380, 650, rec, rec);
rect(200, 470, rec, rec);
rect(290, 560, rec, rec);
rect(110, 380, rec, rec);
rect(110, 290, rec, rec);
rect(110, 200, rec, rec);

}

}

Expert Answer

 int rec = 50;

   void setup() {
size(810, 810);
}

void draw() {
int size = 16;
int dimensions[][] = new int[size][2];
dimensions[0][0] = 380;
dimensions[0][1] = 200;
dimensions[1][0] = 290;
dimensions[1][1] = 110;

dimensions[2][0] = 200;
dimensions[2][1] = 110;
dimensions[3][0] = 470;
dimensions[3][1] = 110;

dimensions[4][0] = 560;
dimensions[4][1] = 110;
dimensions[5][0] = 650;
dimensions[5][1] = 200;

dimensions[6][0] = 650;
dimensions[6][1] = 290;
dimensions[7][0] = 650;
dimensions[7][1] = 380;

dimensions[8][0] = 560;
dimensions[8][1] = 470;
dimensions[9][0] = 470;
dimensions[9][1] = 560;

dimensions[10][0] = 380;
dimensions[10][1] = 650;
dimensions[11][0] = 200;
dimensions[11][1] = 470;

dimensions[12][0] = 290;
dimensions[12][1] = 560;
dimensions[13][0] = 110;
dimensions[13][1] = 380;

dimensions[14][0] = 110;
dimensions[14][1] = 290;
dimensions[15][0] = 110;
dimensions[15][1] = 200;

fill(150);

for(int i=0; i<size; i++) {
rect(dimensions[i][0], dimensions[i][1], rec, rec);
}
}

Still stressed from student homework?
Get quality assistance from academic writers!