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 › methode to reverse gradient fill
Page Index Toggle Pages: 1
methode to reverse gradient fill (Read 1170 times)
methode to reverse gradient fill
Sep 11th, 2007, 3:57pm
 
hi,
I'm afraid that i'm posting a really dumb question, but i've tried to solve the problem alone nearly for an hour, and i get confused more and more, so please help me...

below is the code from Ira Greenberg's book to make a continuous radial gradient;

size(200, 200);
background(0);

for (int i=255; i>0; i--){
 noStroke();
 fill(255-i);
 ellipse(width/2, height/2, i, i);
}

i fully understood how it works, i was very happy about it, and i tried to do some simple modification. Ira's gradient starts from white center and goes darker and darker when expanding to frame. i wanted to make the opposite, darker inside and goes lighter and lighter, i wrote;

size(200, 200);
background(0);

for (int i=0; i<255; i++){
 noStroke();
 fill(0+i);
 ellipse(width/2, height/2, i, i);
}

for me, my code makes sense, but the result is, just big white ellipse.

what did i wrong?? i seriously can not find out what to do beside the code above to reverse the gradient...

thank you.
Re: methode to reverse gradient fill
Reply #1 - Sep 11th, 2007, 4:25pm
 
you are wrong with the assumption that iras code starts from the center. it starts from outside ( black ) and goes to inside ( white ). what happens in your code is that each ellipse is drawn ontop of all others. hence the white ellipse (circle) that remains in the end.

try:

size(200, 200);
background(0);

for (int i=255; i>0; i--){
 noStroke();
 fill(i);
 ellipse(width/2, height/2, i, i);
}
Re: methode to reverse gradient fill
Reply #2 - Sep 11th, 2007, 6:04pm
 
thank you very much fjen,
what I missed is that if i draw ellipses from inside, it will be covered by bigger ellipse, because i draw ellipses with fills, not transparent ellipses!!

but it's still surprising that i never arrived to think that i can simply change the order of fill color...i have to open my head and throw my brain out of the window!! how it's useless!

Page Index Toggle Pages: 1