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 › Variables and color
Page Index Toggle Pages: 1
Variables and color (Read 765 times)
Variables and color
Feb 28th, 2010, 3:17pm
 
I am working through the Learninng Processing book by Daniel Shiffman. The book is good, yet I am having problems understanding the concepts in anything beyond the static images.

The book shows examples of the Fill color being a variable but the book only shows it in black, white, or grey. I put in the following code and got a syntax error. It is probably fairly obvious to someone who is familiar with coding, but I am from a graphic design background and the extent of my programming knowledge is CSS and XHTML. I tried looking through the basics and did not see an example that cleared this issue for me. Please help  Embarrassed
float circle_yX=51;
float circle_yY=138;
float circle_yW=56;
float circle_yH=56;
float circle_yStroke=0;
float circle_yFill= 255, 255, 0;
float change=0.25;

void setup () {
 size (200, 200);
 smooth ();
}
void draw () {
 background (155);
 stroke (0);
 ellipseMode (CENTER);
 
 //yellow ellipse
 circle_yX=circle_yX+change;
 circle_yY=circle_yY+change;
 circle_yW=circle_yW+change;
 circle_yH=circle_yH+change;
 circle_yStroke=circle_yStroke+change;
 circle_yFill=circleyFill+change;
}

Syntax error: maybe missing semicolon?  Cry
Re: Variables and color
Reply #1 - Feb 28th, 2010, 3:41pm
 
the problem is the following.
there are different ways to define a color
this could be

fill(gray) value from 0-255
fill(gray,alpha) same as above with an alpha from 0-255
fill(r,g,b)  you can enter values from 0-255 for red green and blue
fill(r,g,b,alpha)
also  h,s,b, is you are using HSB ColorMode

you can also define special color variables. so you can also use filter with fill(color), fill(color,alpha), or you enter hex values like fill(#000000) for black,

look at http://processing.org/reference/fill_.html
for more information and http://processing.org/reference/color_.html

so there are different things you could do.
you could either define a color variable.
or you can create 3 floats fillR, fillG, fillB, for example.

if you wanna change the color between colors, also lerpcolor could be really usefull http://processing.org/reference/lerpColor_.html
cause interpolating between two colors using the rgb values could be a bit complicated.

Re: Variables and color
Reply #2 - Feb 28th, 2010, 4:18pm
 
I think it's a more basic problem than that, Cedric.

You should read about Processing's "color" variable type.

color myColor = color(255,255,0); // Define a nice yellow color.
fill(myColor); // Draw with yellow.
Re: Variables and color
Reply #3 - Feb 28th, 2010, 4:24pm
 
sure but i wanted to show some more possibilities of using color.
and it seems like he is trying to change the color on runtime, but you can not just add 0.25 to a color variable. So one way would be to change the r,g or ,b value or use lerpcolor for example...
Page Index Toggle Pages: 1