Slowness when drawing many lines
in
Android Processing
•
2 years ago
Hey all, just wondering what your opinion is on this. In my app (which i've posted here) I have some particles that leave trails behind them as they move. The trails are basically points with lines between them, where each point has a variable that slowly decays until the point is deemed (old) and removed from the arraylist. I draw the lines between the points with line(), and I also tried doing it with BeginShape/EndShape and GL_BEGIN, etc, but invariably drawing lines seems to be ridiculously slow. When there are a lot of objects on screen it really lags, if I turn off the trails I can have many times more of the particles on screen, not to mention the particles are circles which should make them pretty expensive as well. I find it hard to believe Processing can do 3d graphics and even shaders and convolution effects, but can't draw lines without falling over.
Am I approaching this wrong or is drawing lines just really expensive? I'm at the point of just taking out the trails completely.
Any thoughts?
Am I approaching this wrong or is drawing lines just really expensive? I'm at the point of just taking out the trails completely.
- //each object has three trails behind it
- for (int i =0; i<tailPoints1.size()-1;i++)
- {
- //points for trail 1
- TailPoint tailCurrent1 = (TailPoint) tailPoints1.get(i);
- TailPoint tailNext1 = (TailPoint) tailPoints1.get(i+1);
- //points for trail 2
- TailPoint tailCurrent2 = (TailPoint) tailPoints2.get(i);
- TailPoint tailNext2 = (TailPoint) tailPoints2.get(i+1);
- //points for trail 3
- TailPoint tailCurrent3 = (TailPoint) tailPoints3.get(i);
- TailPoint tailNext3 = (TailPoint) tailPoints3.get(i+1);
- //draw lines between the points
- //strength is the point's intensity that I use to make the trails fade out towards their end
- //it decreases at a certain rate that I can control, and when it reaches zero the point is eliminated
- stroke(por, pog, pob, tailCurrent1.strength);
- if(stripeCounter%2==0)
- stroke(por,pog+50,pob,tailCurrent1.strength/3);
- line(tailCurrent1.x, tailCurrent1.y, tailNext1.x, tailNext1.y);
- stroke(por, pog, pob, tailCurrent2.strength);
- if(stripeCounter%2==0)
- stroke(por,pog+50,pob,tailCurrent2.strength/3);
- line(tailCurrent2.x, tailCurrent2.y, tailNext2.x, tailNext2.y);
- stroke(por, pog, pob, tailCurrent3.strength);
- if(stripeCounter%2==0)
- stroke(por,pog+50,pob,tailCurrent3.strength/3);
- line(tailCurrent3.x, tailCurrent3.y, tailNext3.x, tailNext3.y);
- }
Any thoughts?
1