hi
i am trying to draw circles on my mainform without to overlap each other.
what i do is i add 50 circles in a loop and on each loop i check if the new circle is overlaping the old circles, if = true it wont be drawn and if = false i draw it and ADD that circle to the list to check it in the next loop.
the problem is that when i want to get the circles from the list i always get the same circle as the new created circle. but why?? i should not get the same coordinate as the new circle!!
something is wrong but i am too tired to understand
this is the code:
i am trying to draw circles on my mainform without to overlap each other.
what i do is i add 50 circles in a loop and on each loop i check if the new circle is overlaping the old circles, if = true it wont be drawn and if = false i draw it and ADD that circle to the list to check it in the next loop.
the problem is that when i want to get the circles from the list i always get the same circle as the new created circle. but why?? i should not get the same coordinate as the new circle!!
something is wrong but i am too tired to understand
this is the code:
B4X:
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 400
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Dim c As Canvas
Type crl(x As Float,y As Float,r As Int)
Dim circle_list As List
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.SetFormStyle("UNIFIED")
MainForm.Show
c.Initialize("canvas")
circle_list.Initialize
MainForm.RootPane.AddNode(c,0,0,600,400)
fill_circles(50)
End Sub
Sub fill_circles(amount As Int)
Dim overlap As Boolean
' Dim circle, old_crl As crl
circle_list.Clear
For i = 0 To amount - 1
Dim circle, old_crl As crl
circle.r = Rnd(2,25)
circle.x = Rnd(0,MainForm.RootPane.Width-(circle.r*2))
circle.y = Rnd(0,MainForm.RootPane.Height-(circle.r*2))
overlap = False
For j = 0 To circle_list.Size - 1
old_crl = circle_list.Get(j)
If distance_x(circle.x,old_crl.x) < circle.r + old_crl.r And distance_y(circle.y,old_crl.y) < circle.r + old_crl.r Then
overlap = True
Exit
End If
Next
If Not(overlap) Then
c.DrawCircle(circle.x,circle.y,circle.r,fx.Colors.ARGB(100,Rnd(0,255),Rnd(0,255),Rnd(0,255)),True,0)
circle_list.Add(circle)
End If
Next
End Sub
Sub distance_x(x1 As Float,x2 As Float) As Float
Return(Abs(x1-x2))
End Sub
Sub distance_y(y1 As Float,y2 As Float) As Float
Return(Abs(y1-y2))
End Sub
Last edited: