I made a try with amnon idea (second post), and I filled all the area, but the impression is not what I was looking for. The first amnon idea produced the impression I wanted, but if I fill all the area, it needs too much time. Maybe the best idea is to generate points with random and after separate them. The purpose of generating the points is to simulate a flow in a pipe. This is my actual version. I simply wanted to simplificate with a better way of generating the points. In my code what I do is separate the balls that were generated with random
class ball{
PVector pos;
PVector v;
PVector force;
color c;
int r=3;
float f = 0.1;
float g = 0.1;
float vaverage = 2;
ball(int x0, int y0){
pos=new PVector(x0,y0);
v=new PVector(0,4);
force = new PVector (0,0);
}
void update(){
v.y = vaverage * (1 - sq(pos.x - middle)/sq(pipediam/2));
v.add (force);
//add some chaos
v.x = v.x + random(-0.3,0.3);
count++;
//v.y = v.y + g ;
pos.add(v);
v.x = v.x*0.5;
force.x = 0;
force.y = 0;
}
void render(){
//if (abs(x.x-middle)<0.4 * pipediam){
fill(20,20,2000);
ellipse(int(pos.x),int(pos.y),2.5,2.5);
if ((pos.y > respoint - reslenght/2)&& (pos.y > respoint + reslenght/2)){
}
//}
}
}
float count;
int width=800;
int height=600;
float g=2;
ArrayList balls= new ArrayList();
float k=1;//factor to increment distance between balls
float c= 4;//maximun penetrance in walls
float vlim=10;//maximum speed
float population=1000;//population limit
float suck = 10;// distance of influence
float leftborder;
float rightborder;
float visc;
float pipediam = 100;
float middle;
float repulsion = 0.1;
float reslenght = 50;
float respoint;
void setup(){
noStroke();
//frameRate(48);
size(800,600);
leftborder = width/2-pipediam/2;
rightborder = width/2 + pipediam/2;
middle =(leftborder + rightborder)/2;
respoint = height/2;
for (int i = 0; i < population; i++){
balls.add(new ball(int(random(leftborder,rightborder)), int(random(0,height))));
}
}
void draw(){
fill (250,100);
rect(0,0,width, height);
for(int i=0;i<balls.size();i++){
ball b = (ball) balls.get(i);
//separate from walls
if(b.pos.x>rightborder-b.r+c){b.pos.x=rightborder;}
if(b.pos.x<leftborder + b.r-c){b.pos.x=leftborder;}
if(b.pos.y>height-b.r+c){b.pos.y-=5;}
//repulsion between balls
for(int j=i+1;j<balls.size();j++){
ball b2 = (ball) balls.get(j);
PVector dx=PVector.sub(b2.pos,b.pos);
if (dx.mag() < suck){
dx.normalize();
dx.mult(repulsion);
b2.force.add( dx);
dx.mult(-1);
b.force.add( dx);
}
}
//repulsion to walls
if (b.pos.x < suck + leftborder){
b.force.x = b.force.x + repulsion;
}
if (b.pos.x > rightborder - suck){
b.force.x = b.force.x - repulsion;
}
b.update();
// corrections
if (b.v.y < 0){b.v.y = 0;}
b.render();
if (b.pos.y > height){
b.pos.y = 0;
}
}
}