Reputation: 33
So the idea is this: I have an input , as the user types a value I want to draw circles on the screen (see picture).
I want the circles to start from mid screen and if the user types another value to re draw the circles accordingly.
I know how to draw but I am not quite certain how the math for what I want to achieve is done.
P.S. I wrote code to auto size the circles if the user enters more than the number that fit the screen, but if he enters less than that I want the circles to be drawn from mid outwards.
C# , WinForms
Upvotes: 1
Views: 538
Reputation: 549
It's pretty simple maths in the end. Assume
diameter is 100 pixels
Buffer between circles is half-radius (50 pixels)
Width of screen is 800 pixels
Height of screen is 600 pixels
--Initial position:
first position: (width / 2, height / 2 - (circles-1) * (diameter + buffer) / 2))
--All subsequent positions:
next position: (previousposition.x, previousposition.y + diameter+ buffer)
if you enter 1 circles it would be:
circle 1: (400, 300 - (0 * (radius+buffer)/2 = (400, 300)
If you enter 2 circles it would be:
circle 1: (400, 300 - (1 * (radius+buffer)/2 = (400, 225), circle 2: (400, 225 + 150) = (400, 375)
If you enter 3 circles it would be:
circle 1: (400, 300 - 2*radius+buffer)/2 = (400, 150), circle 2: (400, 150 + 150) = (400, 300), circle 3: (400, 300 + 150) = (400, 450)
... and so on.
Upvotes: 1
Reputation: 133
If I understood correctly you are looking for something like this:
var Start = Height / 2 - NumberOfCircles * CircleSize;
for (int i = 0; i < NumberOfCircles; i++)
{
Draw(Start + (i * CircleSize));
}
PS: Use the variable CircleSize
for the actual size of the circle plus some space, and in the function Draw
you can manage where the circle is going to be drawn
Upvotes: 1