Hello! I would love to know how can i draw circles in random positions but without them getting in the way of each other. I want them to be seperated at least 50 pixels from each other but without them leaving the boundaries of the Picture Box. Please help me out with this i would be so greatful!!
This is my code and its close but it doesnt do it!
This is my code and its close but it doesnt do it!
C#:
private void btnCrear_Click(object sender, EventArgs e) {
objDraw.Clear(Color.AliceBlue);
Amount = Convert.ToInt16(txtNodos.Text);
SolidBrush SBColors = new SolidBrush(Color.Black);
for (int i = 0; i < Amount; i++)
{
PosX = objNum.Next(100, 700);
PosY = objNum.Next(100, 300);
if (i > 0)
{
if (PosXB + 50 < 700 && PosYB + 50 < 300)
{
if (PosX > PosXB + 50 && PosY > PosYB + 50)
{
objDraw.FillEllipse(SBColors, PosX, PosY, 50, 50);
PosXB = PosX;
PosYB = PosY;
MessageBox.Show("1");
}
else
{
objDraw.FillEllipse(SBColors, PosX+50, PosY+50, 50, 50);
PosXB = PosX+50;
PosYB = PosY+50;
MessageBox.Show("2");
}
}
else if (PosXB - 50 > 100 && PosYB - 50 > 100)
{
if (PosX < PosXB - 50 && PosY < PosYB - 50)
{
objDraw.FillEllipse(SBColors, PosX, PosY, 50, 50);
PosXB = PosX;
PosYB = PosY;
MessageBox.Show("3");
}
else
{
objDraw.FillEllipse(SBColors, PosX-50, PosY, 50, 50);
PosXB = PosX-50;
PosYB = PosY-50;
MessageBox.Show("4");
}
}
}
else
{
objDraw.FillEllipse(SBColors, PosX, PosY, 50, 50);
PosXB = PosX;
PosYB = PosY;
}
}