really stumped on the logic of creating as many squares as possible...

I am trying to do something perhaps simple yet complex…

Process:

I start processing
I am queried for how many rectangles I want
I enter a number such as 5
Processing creates 5 rectangles 50 pixels apart, if the width isn’t enough to have all 5 rectangles in one row then another row is created under
I should have 5 rectangles

I am really confused because I am a beginner to processing and never really had to think so deep about such problems…

I have been trying this:
void setup()
{
size(600,600);
//I choose 100 as the number of elements because I assume that anymore elements than this are too small to be visible on the screen,
//I am aiming to draw a typical rectangle that is 50 pixels in width and 70 pixels in length.
distances = new float[100][100];

}

float distances;

void draw()
{
inputWidths=(width/amountRecs)-50;
inputHeight=(height/amountRecs)-50;

background(255,255,255);
for(int i=50; i<height; i+=50) {
for(int j=50; j<width; j+=50) {
distances[j] = ;

  • }*
    }
    }
    so basically, amountRecs is the amount of rectangles the user wants from user input.
    inputWidth and inputHeight are subtracted by 50 for that padding space between each rectangle.
    Now this is where I am stuck…from what I THINK, I should be using multidimensional arrays to generate the x and y for each rectangle
    but my problem is I dont know how to create as many rectangles as I can that will fit the screen width and then move to the next row.
    Goal:
    http://imageshack.us/photo/my-images/845/foods.png/

Why don't you ask on the Processing forum rather than a forum devoted to a completely different subject?

Please post your code in a code box, so we can actually read it. Modify your original post, select the code, and delete it. Then, select the icon (above) with the # sign on it, then paste your code again.

Now this is where I am stuck...from what I THINK, I should be using multidimensional arrays to generate the x and y for each rectangle

Sounds reasonable.

but my problem is I dont know how to create as many rectangles as I can that will fit the screen width and then move to the next row.

How would you do this with pencil and paper? You need to decide whether the rectangle width should be fixed, and the number of rectangles per row computed, or whether the number of rectangles should be fixed, and the width of each rectangle computed. You don't have (or have not provided) enough information to compute both the number of rectangles per row and the width of each rectangle.

If there was a minimum width, for instance, that would be sufficient information to allow calculating both.

Once you know the number of rectangles per row, you can determine the width. Once you know the width, you can determine the left origin of each rectangle. Given the left origin, you can compute the right origin (by adding the width and any space between rectangles needed).

Perform the same process for computing the bottom and to location, based on the height of each rectangle.