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 & HelpPrograms › Fading Lines
Page Index Toggle Pages: 1
Fading Lines (Read 690 times)
Fading Lines
Aug 22nd, 2009, 9:23pm
 
Hi. I was reading the examples and trying to draw a line that will fade way begining from one of its point and vanishing more and more parts until the other point is reached. Something like the way the "comet"´s tail fades on the Reflection1 Example that comes with processing. I couldn´t figure out how to do this on processing. Does anyone have any suggestion about this algorithm?

Thanks
Re: Fading Lines
Reply #1 - Aug 22nd, 2009, 10:59pm
 
you can easily achieve this effect by drawing semitransparent rects instead of background();

read more about this "hack" : http://processing.org/hacks/hacks:fading

if you have more objects and want the fading only on one of them its getting more complicated and you have to do something like this.

old example, but hope it gives you an idea:

Code:
void setup(){
 size(400,400);
 background(255);
 frameRate(40);

 for(int i=0; i<anzahl; i++){
   oldX[i] = 0;
   oldY[i] = 0;
 }
}

int anzahl=9;
float[] oldX = new float[anzahl];
float[] oldY = new float[anzahl];

void draw(){

float[] tmpX = new float[anzahl];
float[] tmpY = new float[anzahl];
 for(int i=0; i<anzahl-1; i++){
   tmpX[i+1] = oldX[i];
   tmpY[i+1] = oldY[i];
  }
  tmpX[0]=mouseX;
  tmpY[0]=mouseY;
 
  oldX=tmpX;
  oldY=tmpY;
   
background(255);
 for(int i=0; i<anzahl-1; i++){

  stroke(255/anzahl*i);
  strokeWeight(10+20*(1-i/float(anzahl)));
   line(oldX[i],oldY[i],oldX[i+1],oldY[i+1]);

 }
}


Page Index Toggle Pages: 1