简体   繁体   English

C#如何从屏幕中心向外动态绘制圆

[英]C# How to draw circles from center of screen outwards dynamiclly

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). 所以这个想法是这样的:我有一个input,当用户输入一个值时,我想在屏幕上绘制圆圈(参见图片)。

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. 我知道如何绘画,但我不确定要完成的数学运算是如何完成的。

PS 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. PS:如果用户输入的数字大于适合屏幕的数字,我编写了自动调整圆圈大小的代码,但是如果用户输入的数字少于该数字,我希望从中间向外绘制圆圈。

C# , WinForms C#,WinForms

在此处输入图片说明

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 PS:将变量CircleSize用作圆的实际大小加上一些空间,在Draw函数中,您可以管理圆的绘制位置

It's pretty simple maths in the end. 最后,这是非常简单的数学。 Assume 假设

diameter is 100 pixels 直径为100像素

Buffer between circles is half-radius (50 pixels) 圆之间的缓冲区是半半径(50像素)

Width of screen is 800 pixels 屏幕宽度为800像素

Height of screen is 600 pixels 屏幕高度为600像素

--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: 如果输入1个圆圈,则为:

circle 1: (400, 300 - (0 * (radius+buffer)/2 = (400, 300) 圆1: (400,300-(0 *(半径+缓冲区)/ 2)=(400,300)

If you enter 2 circles it would be: 如果输入2个圆圈,则为:

circle 1: (400, 300 - (1 * (radius+buffer)/2 = (400, 225), circle 2: (400, 225 + 150) = (400, 375) 圆1: (400,300-(1 *(半径+缓冲区)/ 2)=(400,225), 圆2: (400,225 + 150)=(400,375)

If you enter 3 circles it would be: 如果输入3个圆圈,则为:

circle 1: (400, 300 - 2*radius+buffer)/2 = (400, 150), circle 2: (400, 150 + 150) = (400, 300), circle 3: (400, 300 + 150) = (400, 450) 圆1: (400,300-2 *半径+缓冲区)/ 2 =(400,150), 圆2: (400,150 + 150)=(400,300), 圆3: (400,300 + 150) =(400,450)

... and so on. ... 等等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM