Regarding the lack of having the grid in centre, that is my bad.
You need to add, to the x and y coordinates, half of the width/height you want to use as a margin.
You had in your initial code
width*0.875, which I guess you did do only draw on 87.5 percent of the width.
So, we need to add to x half of the margin, to move it to the right.
So, half of 12.5% of the width, or to write it out in math
- float marginX = (width * (1 - 0.875)) / 2.0;
and Y
- float marginY = (height * (1 - 0.875)) / 2.0;
So that when you then draw it will be:
- ellipse(x + marginX, y + maginY....
As for the size, you need to figure out the ratio between width/height to know the number of rows/columns.
I am maybe making this a bit more complicated for you than what it could be.
BUT, for the size of the ellipses, use the same calculation on both width and height:
eg.
- ellipse(x + marginX, y + marginY, colWidth*0.75, colWidth*0.75);
EDIT:
To get the number of rows to match columns, you can first decide on columns:
- int ellipsesX = 17; // Set number of columns
- float colWidth = (width*0.875)/(float)ellipsesX; // Find column width
- int ellipsesY = (int)((height*0.875)/colWidth); // Find how many rows can fit on height
You only need to calculate colWidth and rowHeight before the loops start.
EDIT2:
To get near pixel perfect matching of width/height/columns/rows, it might be wise to decide on some sizes first.
Say you want 5 columns, and 10 rows, then you should pick a size for the sketch that matches, and just add some pixel value for margin.. Take 50 as a size for the ellipses. width = 5*50 + margin, height = 10 * 50 + margin
Let margin be 500 on each side.. we'll get width = 750 and height = 1000
then you calculate colWidth = (width-500)/(float)ellipsesX, instead of doing the *0.875