Nice to meet you.
Use this site for the first time.
I am worried about not doing anything rude.
I want you to help.
I want all the balls to bounce the wall.
However, only one ball bounces the wall.
Please tell me how to improve it.
This program is trying to realize the following functions.
1 Generate all balls so as not to overlap.
2 I want to move all the balls in any direction.
However, 2 is incomplete.
Only one ball moves.
I would like advice on how to improve it.
I am an amateur of processing.
It has been about three months since I started.
I spent a lot of time and finished the program so far.
The great technology of the great people was also helpful.
However, you can not bounce more than one ball.
I understand that I have a lack of study.
However, I would like you to lend me some power to move forward.
Thank you in advance.
`type or paste code here`
ArrayList <PVector> drops0;
PVector location;
PVector velocity;
int num = 10; //num = circles.size()
float r = 10;
float r2 = r*2;
void setup() {
drops0 = new ArrayList <PVector>();
ellipseMode(RADIUS);//RADIUS
frameRate(60);
background(255);
size(1200, 600);
while (drops0.size() < num) {
velocity = new PVector (1, 1);
float xxx = random(r, width-r);
float yyy = random(r, height-r);
location = new PVector(xxx, yyy, r);
boolean overlapping = false;
for (PVector test : drops0) {
if (dist(location.x, location.y, test.x, test.y) < (location.z+2 + location.z+2)) {
overlapping = true;
break;
}
}
if (!overlapping) {
//drops0.add(velocity);
drops0.add(location);
}
}
}
void draw() {
background(255);
noStroke();
move();
}
void move() {
location.add(velocity);
for (int i=0; i < num; i++) {
PVector location = drops0.get(i);
if ( i < 20 ) {
fill(50, 50, 200, 100);
} else if ( i+(20) < num ) {
fill(150, 0, 0, 100);
}
ellipse(location.x, location.y, r, r);
}
if (location.x < r || location.x > width-r) {
velocity.x = velocity.x * -1;
}
if (location.y < r || location.y > height-r) {
velocity.y = velocity.y * -1;
}
}