I want to specify a number and have that number halve itself equally so that the bottom of my canvas fills with rectangles. For instance, if I specified the number 4, the bottom of my canvas would have 4 rectangles, each rectangle smaller than the last, until the bottom half of the canvas was filled. The total size of the rectangles would be approximate to half the size of my canvas.
_______________ | | | | | | | | |_______________| <- middle = 240 |________d______| |________c______| |________b______| | a | | | ---------------
Where a, b, c, and d, represet sections each rectangle. A
would be the largest rectangle, B
would be around half the size of A
, and C
would be around half the size of B
, so that the entirety fills up half of my canvas, etc.
What formula could I use to achieve this?
I'm developing an application and would obviously do each calculation inside of a loop, hence, I would only need to know how to calculate each individual rectangle while plugging in the iteration of my loop. e.g.
totalRects = 4; middle = 240; for(int i = 0; i
Update Using the formula provided in the answer below, the total sum of the pieces don't add up to the mid point:
The black line represents the midpoint of 240.