Hi, I'm trying to produce a sketch that evenly distributes objects at the same distance from one another.

So far I've based the concept of the sketch on a sort of charged particle system.

If particles are to close to each other they repel, to far away, they attract, very far away, they do nothing (wait around essentially).

I've also quickly dropped in the ability to increase or decrease the restraining distances of certain conditions.

But the sketch still wont evenly distribute each particle.

I think it has something to do with the use of float D = dist(n1.x, n1.y, n2.x, n2.y);

Each particle can't be.. lets say spaced 100 pixels from every other particle, because that would result in each fighting for an even point against every other.

Simply,

Any help or discussion will be much appreciated.

float Dist = 100;

float A = 50;

boolean hover = true;

boolean lock = false;

size(900, 900);

smooth();

boids = new ArrayList();

}

background(255);

F = loadFont("Calibri-48.vlw");

fill(0);

smooth();

text("Repel Limit " + A, 20, 20);

text(" Dist " + Dist, 20, 40);

for (int i=0; i<boids.size(); i++) {

Boid b = (Boid) boids.get(i);

b.Drag();

b.Drop();

b.display();

}

for(int i=0; i<boids.size(); i++) {

Boid n1 = (Boid) boids.get(i);

for(int j=0; j<boids.size(); j++) {

Boid n2 = (Boid) boids.get(j);

//noFill();

//stroke(0.25);

//ellipse(n1.x, n1.y, Dist, Dist);

if (dist(n1.x, n1.y, n2.x, n2.y) <= Dist) {

float D = dist(n1.x, n1.y, n2.x, n2.y);

float theta = atan2(n1.y-n2.y, n1.x-n2.x);

if(D > n1.r*2 && D < A) {

n1.x += 1 * cos(theta);

n1.y += 1 * sin(theta);

}

}

if (dist(n1.x, n1.y, n2.x, n2.y) >= Dist && dist(n1.x, n1.y, n2.x, n2.y) <= 200) {

float theta = atan2(n1.y-n2.y, n1.x-n2.x);

n1.x += -1 * cos(theta);

n1.y += -1 * sin(theta);

}

}

}

}

if (mouseButton == LEFT) {

boids.add(new Boid(5, -1, 0));

}

}

switch(key) {

case '=':

Dist += 10;

break;

case '-':

Dist -= 10;

break;

case '2':

A += 10;

break;

case '1':

A -= 10;

break;

}

}

float x, y;

float r;

float C;

color c;

Boid (float R_i, float Charg, color col_i) {

r = R_i;

x = mouseX;

y = mouseY;

C = Charg;

c = col_i;

}

if (mouseButton == CENTER && mouseX > x-dis && mouseX < x+dis &&

mouseY > y-dis && mouseY < y+dis) {

lock = true;

x = mouseX;

y = mouseY;

}

else {

if (mouseButton == LEFT && mouseX > x-dis && mouseX < x+dis &&

mouseY > y-dis && mouseY < y+dis) {

lock = false;

}

}

}

lock = false;

}

void display() {

stroke(0);

strokeWeight(1);

fill(150,70);

ellipse(x, y, r*2, r*2);

noFill();

stroke(255,51,51,60);

ellipse(x, y, Dist, Dist);

fill(c);

//text(x + " / " + y,x+10,y);

}

}