The problem is that whilst an agent in proximity to another agent may have its colour changed by the condition, because it is not in proximity to another agent the condition in that loop changes it back to white.
To put it another way:
Agent A is near agent B so agent A and B are set to black.
However, neither A or B are near to agent C and since this is the last agent in the loop it changes the colours of A and B back to white.
There's a simple way around this problem. Set the value of a boolean to false outside the inner 'k' loop which checks distance. If the agent is near to another agent set the boolean to true otherwise do nothing. So just to labour the point: if it is near to ANY other agent the boolean will be true, otherwise it will be false. Then simply test against the boolean to determine the colour:
Code:float[] x;
float[] y;
float[] distance_points;
int numPoints = 10;
float colorr[];
void setup()
{
size(300, 300);
x = new float[numPoints];
y = new float[numPoints];
distance_points = new float[numPoints];
colorr = new float[numPoints];
for (int i = 0; i < numPoints; i++) {
x[i] = random(242);
y[i] = random(282);
distance_points[i] = 0;
colorr[i] = 0;
}
}
void draw() {
background(250);
for (int i = 0; i < numPoints; i++){
x[i] = x[i] + random(2) - 1;
y[i] = y[i] + random(2) - 1;
fill(colorr[i] );
ellipse(x[i], y[i], 20, 20);
boolean near = false;
for (int k = 0; k < numPoints; k++){
if ( i != k) {
distance_points[k] = dist(x[k] , y[k] , x[i] , y[i]);
}
if (distance_points[k] < 40) {
near = true;
}
}
if(near){
colorr[i] = 0;
}
else {
colorr[i] = 250;
}
}
}
Note that you had also checked against distance_points[i] and not distance_points[k]. It's late here so I'm not going to try and explain that now...