I have some code that generates particles at random locations, and moving in random directions and speed.
Each iteration through a loop, I move all the particles, and call repaint on my jpanel.
For 1,000 particles, I'm getting around 20 to 30 frames per second. I plan to eventually have 100,000 to 1,000,000 particles.
In paint, I only create a new bufferedimage if the window has changed size. I draw the pixels to the bufferedimage, and then call drawImage to display the image.
Each particle is a single pixel, and I have determined that all the time is taken up actually drawing the pixels. So, increasing the number of particles will drastically reduce the frame rate.
I've tried g.drawline(x,y,x+1,y), img.setRGB(x,y,color), getting an array of pixels by calling img.getRaster().getDataBuffer().getData(), then setting pixelData[y*width+x] = color.
I only get a small difference in the frame rate with these different ways of drawing the pixels.
Here's my question: What is the fastest way to draw pixels? Is bufferedimage even the way to go?
Thanks.