We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Breaking up beginShape(LINE_STRIP)   endShape
Page Index Toggle Pages: 1
Breaking up beginShape(LINE_STRIP)   endShape (Read 1020 times)
Breaking up beginShape(LINE_STRIP)   endShape
Apr 19th, 2006, 5:42pm
 
Is there any possibility of breaking up the beginShape(LINE_STRIP) / endShape() block into different frames?

The thing is I'm trying to draw linestrips with many many vertex, and don't want to hold them all in memory.  I guess (only a guess) that a renderer should be capable of drawing a line strip without needing to hold all the points in memory, maybe only the last one.

This wouldn't matter if I was drawing with an alpha value of 255, but since I'm drawing transparent lines, if I draw separate lines you can easily see the joints between to concatenated lines.

I hope I'm explaining myself enough.  Here's some code example:

Quote:

float MINNERVE = 0.001;
float MAXNERVE = 0.005;

float MININERTIA = 0.8;
float MAXINERTIA = 1.1;

float maxvel = 8;
float maxalph = 0;


Particle pepe;

void setup(){
 size(300,300);
 framerate(25);

 background(255);
 smooth();

 strokeWeight(7);

 pepe = new Particle(g);
}

void draw(){
 noStroke();
 fill(255,10);
 rect(0,0,width,height);

 for(int i=0; i < 12; i++){
   pepe.update(mouseX,mouseY);
   pepe.draw(g);
 }
}

void mousePressed(){
 pepe.setPos(mouseX,mouseY);
 maxalph = 255;
}

void mouseReleased(){
 maxalph = 0;
}

public class Particle{
 // Velocity
 float velx, vely;

 // Position
 float posx, posy;
 float lastposx, lastposy;

 // Caracteristics
 int col;
 float sz;

 // Constructor
 public Particle(PGraphics gfx){
   posx = random(-gfx.width/2,gfx.width/2);
   posy = random(-gfx.height/2,gfx.height/2);
   lastposx = posx;
   lastposy = posy;
   velx = 0;
   vely = 0;

   colorMode(HSB);
   sz = random(2,3);
 }

 // Updater of position, velocity and colour depending on a RGroup
 public void update(float x, float y){
   lastposx = posx;
   lastposy = posy;

   posx += velx;
   posy += vely;

   float distancia = dist(posx,posy,x,y);

   float distPointx = x - posx;
   float distPointy = y - posy;

   float rand = random(MINNERVE,MAXNERVE);

   distPointx *= rand;
   distPointy *= rand;

   rand = random(MININERTIA,MAXINERTIA);
   velx *= rand;
   vely *= rand;

   velx += distPointx;
   vely += distPointy;

   float velnorm = constrain(norm(velx,vely),0,maxvel);
   float sat = abs(maxvel - velnorm)/maxvel*maxalph;
   col = color(0,0,1,sat);

 }

 public void setPos(float newposx, float newposy){
   lastposx = posx;
   lastposy = posy;
   posx = newposx;
   posy = newposy;
 }

 // Drawing the particle
 public void draw(PGraphics gfx){
   stroke(col);
   if(alpha(col)>50)
     line(lastposx,lastposy,posx, posy);
 }
}

float norm(float x1, float y1){
 return sqrt(x1*x1 + y1*y1);
}




I would like to avoid drawing a line each time I redraw the particle, and instead only make a call to vertex, and let the renderer interpolate between vertexes alphas, etc. at least between the last vertex drawn and the new one.

Could this be possible in the future? Any ideas for the meantime to avoid the joints when drawing fast?
Page Index Toggle Pages: 1