Thousands of ellipses slows Processing down

Hi I’m new to Processing and I’m dabbling with the example: Circle Collision with Swapping Velocities by Ira Greenberg : Circle Collision with Swapping Velocities / Examples / Processing.org

I can post the code if you like but this is a general question about Processing performance slowing down.

That example has just 2 balls moving around the screen and bouncing off each other as well as off the edges of the canvas. Each ball is an instance of new Ball(x, y, r_(radius)) and draws an ellipse:

void display() {
    noStroke();
    fill(r,g,b);
    ellipse(position.x, position.y, radius*2, radius*2);
  }

I changed my version by using a for loop to add lots of instances of new Ball() and it works well. I can have hundreds of balls (or in my case particles) bouncing off each other. The problem comes when I start adding thousands. When the balls start moving everything slows down.

Is this just stretching the boundaries of my processor or is there a better way to draw the ellipses so that I can have thousands moving around the screen? Should I try to create some kind of reusable symbol or something? I have tried increasing the available memory in preferences but nothing changes.

Thanks.

Try using the FX2D renderer: size(width, height, FX2D).

I’ve found that it renderers primitives much more quickly than the default one.

Thanks very much I’ll give that a try.

Yeah it didn’t work but I got closer to the cause of the problem. It’s not the drawing of the ellipses that is slowing it down but the functions to calculate the balls bouncing off the walls and off each other that is the problem. Those functions are lifted straight from the example and I suspect there’s no way to do it better. The more times those functions are calculated the slower everything gets. It’s perfect for hundreds but into the thousands and it struggles. I suspect I need better hardware as well as maybe software that is built to deliver this sort of thing.