Hej,
I'm drawing a huge number of ellipses and rects saved as objects in an arraylist, what slows down the framerate.
Code:public void draw(){
for (int i = 0; i < ellipses.size()-1; i++) {
Ellipses Circle = (Ellipses) ellipses.get(i);
ellipse(Circle.getX(),Circle.getY(), 3, 3);}
for (int i = 0; i < squares.size()-1; i++) {
Rect quad = (Rect) squares.get(i);
rect(quad.getX(),quad.getY(), 3, 3);}
...}
Does anybody know wether there is a way to do the two "for loops" simultaneously?
I tried some kind of threading. In Example: One thread draws an ellipse and the other thread a rect.
Code:
public class RectThread extends Thread {
PApplet parent;
Code:
public RectThread (PApplet p){
parent = p;
...}
Everything in the "while loop" is repeated forever until the variable "running" is false or the thread is stopped what actually is the same.
Code:public void run ()
{
while (running==true){
if (drawBoole==true){
parent.rect(100,100,10,10);
drawBoole=false;
}
}
System.out.println(id + " thread is done!");
}
The draw() manipulates drawBoole trying to synchronize
Code:public void draw() {
background(255);
fill(0);
thread1.drawBoole=true;
thread2.drawBoole=true;
...}
All in all its roughly works. I can see both rect and ellipse but with a lot of flickering background.
I hope, I explained it understandable and would be glad if someone has a solution or a thought-provoking impulse
Thank a lot, fejngold