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 › gradient question
Page Index Toggle Pages: 1
gradient question (Read 477 times)
gradient question
May 13th, 2009, 5:41pm
 
hi board

i'm trying to make a line that fades in and out at the ends... i don't understand why this piece of code doesn't do the trick!

int iii = 1;

void setup(){
 size(600, 400);
 background(0);
 frameRate(30);
}

void draw(){
 background(0);
 strokeWeight(0.5);

for (int i = 0; i < mouseY; i = i + 1){
for (int ii = 0; ii < 255; ii = ii + iii){
 if(ii == 255){
   iii = -1;}
 stroke(ii);}
 point(10, i);
}
}


please give me some tips!
Re: gradient question
Reply #1 - May 13th, 2009, 6:04pm
 
didnt take a closer look at it. Btw i ii and iii is confusing... just use some other letters or numbers.

you can at least add a gradient from the top if you change stroke to stroke(i); cause right now you count it up up to 255 before it "reaches" the point, so thats why its always white.
Re: gradient question
Reply #2 - May 13th, 2009, 6:20pm
 
yes i tried stroke(i); it worked fine but i need a separate int that fades in from zero to 255 and out to zero again.

so now the code is already at 255 when it reaches the point(), making every single point white, right?

how would i make the program draw points forming a line, changing the stroke color value each time a new point is drawn?

thanks for any suggestions!
Re: gradient question
Reply #3 - May 14th, 2009, 2:06am
 
I'm still not sure I understand what you're trying to achieve.  The following code gives two possible options.

Code:
int grey;
void setup(){
size(600, 500);
background(0);
frameRate(30);
}

void draw(){
background(0);
strokeWeight(0.5);

// Will work up to height = 255*2
for (int i = 0; i < mouseY; i++){
   if(i<255) {
    stroke(i);
   }
   else {
    grey = 255 - (i-255);
    stroke(grey);
   }
  point(10, i);
}

// Fades in to the height of the window
for (int i = 0; i < mouseY; i++){
   float input = i;
   grey = 255 - round(((height-input)/height) * 255);
   println(grey);
   stroke(grey);
   point(20,i);
}
   
}


If you want the line to fade in and out then you might want to look at passing the value of (height-input)/height [from the second for loop] to sin and tweak it as necessary to get the shade of grey you need at each point...
Page Index Toggle Pages: 1