In any form of animation there are 2 parts - calculating the new state/position and drawing the current state. To speed up the simulation you have to either optimise the state calculation or find a better way to do the drawing.
Quote:Every object reacts with all the others in every step of the "void draw" loop.
does this mean you are doing the state calculations in the draw() method?
There are approachs to the problem
- calculate the state of an object
- redraw the current state
- repeat for each object
and
- calculate the state of an object
- repeat for each object
- draw the current state
The problem with the first approach it all has to be done in the draw() method and if as in your case the state calculations are large then it is not surprising you get flikering.
A possible solution is to use the second approach which can be done in Processing with
Code:
void setup(){
// blah blah blah
registerPre(this);
}
void pre(){
// do all the state calculations here
}
void draw(){
// draw the objects here
}
With regard to JAVA2D vs P2D.
In the source code comments for PGraphics2D and PGraphicsJava2D it states P2D is better than JAVA2D if you are working at the pixel level but is less accurate than JAVA2D for drawing shapes. Looking at the code for drawing a rectangle in these two classes P2D is doing a lot more work than JAVA2D
In this case perhaps it you should stick with JAVA2D .