Ok I spotted two bugs. One with the boundary box conditions, the other with a wrong loop (or bracket).
Working code:
int num_points_dropplet = 1000;
int num_points_dropplet_2 = 10;
float[] x = new float[num_points_dropplet];
float[] y = new float[num_points_dropplet];
float[] x_2 = new float[num_points_dropplet_2];
float[] y_2 = new float[num_points_dropplet_2];
float[] dist_array = new float[num_points_dropplet];
float the_min = 1000;
int min_index = 0;
float distance_x;
float distance_y;
int count = 0;
int box_x = 10;
int box_y = 1000;
void settings() {
System.setProperty("jogl.disable.openglcore", "true");
size(box_x, box_y, P2D);
}
void setup() {
frameRate(2);
background(0);
noFill();
for (int i = 0; i<num_points_dropplet; i++) {
float radius = random(15);
float a = random(TWO_PI);
x[i] = -box_x/8.0 + cos(a)*radius+random(-radius/10.0, radius/10.0);
y[i] = -box_y/8.0 + sin(a)*radius+random(-radius/10.0, radius/10.0);
stroke(255);
strokeWeight(2);
}
for (int j = 0; j<num_points_dropplet_2; j++) {
float radius = random(10);
float a = random(TWO_PI);
float x_offset_2 = box_x/2.0;
float y_offset_2 = box_y/2.0;
x_2[j] = x_offset_2 + cos(a)*radius+random(-radius/10.0, radius/10.0);
y_2[j] = y_offset_2 + sin(a)*radius+random(-radius/10.0, radius/10.0);
stroke(255, 0, 0);
strokeWeight(3);
}
}
void draw() {
background(0);
translate(width/2, height/2);
for (int i=0; i<num_points_dropplet; i++) {
float radius = random(15);
float a = random(TWO_PI);
x[i] += cos(a)*radius+random(-radius/10.0, radius/10.0);
y[i] += sin(a)*radius+random(-radius/10.0, radius/10.0);
if (x[i] <-box_x/2) {
x[i] = -box_x/2;
}
if (x[i] >box_x/2) {
x[i] = box_x/2;
}
if (y[i] <-box_y/2) {
y[i] = -box_y/2;
}
if (y[i] >box_y/2) {
y[i] = box_y/2;
}
stroke(255);
strokeWeight(2);
point(x[i], y[i]);
}
for (int j=0; j<num_points_dropplet_2; j++) {
the_min = 100000; // reset value, otherwise the dots all agglutinate.
for (int i=0; i<num_points_dropplet; i++) {
dist_array[i] = dist(x[i], y[i], x_2[j], y_2[j]);
// return the index of the min of the distances
if (dist_array[i] < the_min) {
the_min = dist_array[i];
min_index = i;
}
}
float radius = random(1);
float a = random(TWO_PI);
// Move each point a little bit toward the other group's closest point.
distance_x = x[min_index] - x_2[j];
if (distance_x >0) {
x_2[j] += cos(a)*radius + distance_x / 100.0;
} else {
x_2[j] += cos(a)*radius + distance_x / 100.0;
}
distance_y = y[min_index] - y_2[j];
if (distance_y >0) {
y_2[j] += sin(a)*radius + distance_y / 100.0;
} else {
y_2[j] += sin(a)*radius + distance_y / 100.0;
}
if (x_2[j] <-box_x/2) {
x_2[j] = -box_x/2;
}
if (x_2[j] >box_x/2) {
x_2[j] = box_x/2;
}
if (y_2[j] <-box_y/2) {
y_2[j] = -box_y/2;
}
if (y_2[j] >box_y/2) {
y_2[j] = box_y/2;
}
stroke(255, 0, 0);
strokeWeight(3);
point(x_2[j], y_2[j]);
}
}