boolean evo_step() { int vc; Circle old_c, new_c; float md, x, y; // choose a random circle vc = int(random(n_circles)); old_c = circles[vc]; // make new circle with radius and color of old one x = constrain(old_c.x + random(-max_move, max_move), old_c.r, width-old_c.r); y = constrain(old_c.y + random(-max_move, max_move), old_c.r, height-old_c.r); new_c = new Circle(x, y, old_c.r, old_c.c); circles[vc] = new_c; // calculate new overlap values md = min_dist(); if (md < last_min_dist) { // switch back circles[vc] = old_c; return false; } // keep changes last_min_dist = md; println(md); return true; } // calculate minimum distance between circle borders (may be negative!) float min_dist() { Circle a, b; float d = 100000.0, tmp; for (int i = 0; i < n_circles; i++) { a = circles[i]; for (int j = i+1; j < n_circles; j++) { b = circles[j]; tmp = dist(a.x, a.y, b.x, b.y) - a.r - b.r; if (tmp < d) d = tmp; } } return d; }