so I’m working on code and I’ve created a falling circle code. right now the circle have random diameter, speed, color, and etc. I’m trying to make the circles interact for a project. every time the circles overlap they should either bounce our change color. I’m trying to make a code for either one, but I’m kinda stuck. any help?
code:
Circle [] circles = new Circle [10];
class Circle
{
float x;
float y;
float speed;
float diam;
color c;
boolean valid;
final int MAX_COLOR = 255;
final int MIN_X = 50, MAX_X = 750;
final int MIN_Y = -300, MAX_Y = -100;
final int MIN_SPEED = 1, MAX_SPEED = 3;
final int MIN_DIAM = 70, MAX_DIAM = 110;
Circle()
{
initALL();
}
void initALL() {
valid = true;
c = color(random(255), random(255), random(255));
x = random(MIN_X, MAX_X);
y = random(MIN_Y, MAX_Y);
speed = random(MIN_SPEED, MAX_SPEED);
diam = random(MIN_DIAM, MAX_DIAM);
}
void update() {
if (!valid) {
initALL();
return;
}
move();
draw_ellipse();
}
void draw_ellipse()
{
fill(c);
ellipse (x, y, diam, diam);
}
void move()
{
if (y-diam <= height)
{
y += speed;
} else if (y-diam > height )
{
valid = false;
}
}
}
void setup() {
size (1000, 600);
for (int i = 0; i < circles.length; i++)
{
circles[i] = new Circle();
}
}
void draw() {
background(100, 100);
for (Circle s : circles ) {
s.update();
}
}