In my app, I have a bunch of rectangles.
![enter image description here](https://i.stack.imgur.com/P2n6i.png)
I am trying to horizontally centerize all of these rectangles on the screen. (The center is screen_width/2)
Here is my code so far (for your viewing pleasure),
for (var j=0;j<rectangles.length;j++){
rectangle=rectangles[j];
var margin=120;
var coefficent=0;
var center_index=Math.ceil(rectangles.length/2);
if (j>center_index){
coefficent=1;
}else if (j<center_index){
coefficent=-1;
}
var x=(screen.width-rectangle.width)/2+j*margin*coefficent;
rectangle.SetX(x);
}
This code puts everything in the center (not cool).
Any help on this problem would be splendidly appreciated.
Edit:
Sorry for not being clear,
Heres another image to be more clear (the line, is the center line):
![enter image description here](https://i.stack.imgur.com/kJuL7.png)
So you can see, that we are shifting all the rectangles so that the middle rectangle is in the center.
Like when you press the center button to centerize text horizontally on a Word Document, I am trying to do this with rectangles.