Trying to create random circle that does not overlap

Thanks for all the help i managed to understand your example.
However, if I were to change the code to include array I am not able to understand how to write a code which checks the new value with all previous value in the array. Does anyone have a tip for this.

Do you mean a fixed array?
I just took a look at the examples @paulgoux provided.
In the first two, an object ArrayList was used and the third used a (variable) js var object.
This is because you don’t know how big the array needed, has to be.
The whole process of distance measuring is very slow, so the lesser objects to be handled, the better.
That’s why I also used a (size variable) FloatList.
But I respect the spirit of trying to do it your own way, so let’s see your code above.

  • You are creating two fixed float arrays for the x/y values in every frame of the draw() loop.
  • Then you start another loop giving random x/y values to the arrays.
  • The following step is creating a second nested loop, and again you are giving random values to the same x/y arrays and measuring the distance between them.

I’ll stop here because this will always will be 0,0 and the following if block will always be true.
You can test this by writing println(variable); above the ‘if’ conditional line and below.
The best thing you can do is to first write down these points on paper, and check if the logical order of what you are planning to do is correct. Then, when coding, place as much as println(variables) as you can, or use Processing’s Debug feature.

Hello,

There are examples on the Processing website for multiple objects:
image

The Flocking one separates the birds.

:)

Ah well…2 cents:

  1. You should terminate the while(overlap) loop, or it might get endless when the screen fills up
  2. Why not use PVector?
1 Like

Hehe. That’s right, I just put it together too fast :grinning:
It should also have used a ‘growth’ factor to fill the whole screen with smaller circles.
But I don’t have time at the moment for this kind of stuff, because I’m too busy to rewrite all my Android code for my new Android 10 phone. That’s why I, although anxious, didn’t try your Android OpenCV library yet. Android 10 changed a lot of security rules, making it even more difficult. Paulgoux managed to adapt the code, to still open the image explorer without using the newly introduced Scoped Storage approach. But it will be mandatory on Android 11, so there is no way around. Maybe you want to join us there.