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 › Newbie// How to use color
Page Index Toggle Pages: 1
Newbie// How to use color (Read 320 times)
Newbie// How to use color
Mar 16th, 2009, 6:00pm
 
Hi,

I am starting to learn Processing, using the Basic Tut. Now I watch the "Functions" example:

void drawTarget(int xloc, int yloc, int size, int num)
{
 float grayvalues = 100/num; // 255/num = Anzahl Graustufen max., je kleiner desto dunkler
 float steps = size/num;
 for(int i=0; i<num; i++) {
   fill(i*grayvalues);
   ellipse(xloc, yloc, size-i*steps, size-i*steps);
 }

The targets are grayscale, I'd like to learn about changing the colors to e.g. reddish. Using the color selector has no effect, changing the word grayvalues to redvalues has no effect, in fact nothing has any effect on colors. I surely dont see the solutin and would be glad to learn how stupid I am...

And by the way: what does "xloc" stand for? I didnt find it in the references.

With best regards,

Peter
Re: Newbie// How to use color
Reply #1 - Mar 16th, 2009, 6:13pm
 
xloc isn't a keyword, it is just the name of a parameter, you can rename it mariosBros if you want (but then, change all occurrences!). I think it means that's a horizontal (x) position (location).

Likewise "grayvalues" name has no weight on the program itself, you can rename it "rainbowHues" without changing anything.
The key here is to use another form of fill() call:
fill(red, green, blue) where the color names are variables (or values) giving the amount of color for each component.
You can try and change the fill call with fill(i*grayvalues, 0, 0); to get reddish colors. Or fill(i*grayvalues, 255, 255); to have clearer colors. And so on.
Re: Newbie// How to use color
Reply #2 - Mar 16th, 2009, 9:43pm
 
Yep, that's what I was looking for... Thanks, I can now learn more.

So, to ask once again:
the line
float grayvalues = 100/num;
has nothing to do with color, simply specifies a variety of color or grayscale, and only the fill line is the line that adresses color specs. Correct?
Re: Newbie// How to use color
Reply #3 - Mar 17th, 2009, 10:35am
 
Yes, correct. grayvalues is only a number, a quantity. It has a meaningful name, which is good practice, but its value can be used as font size as well, for example.
Page Index Toggle Pages: 1