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 › Passing a Hex value into Fill in a function
Page Index Toggle Pages: 1
Passing a Hex value into Fill in a function (Read 294 times)
Passing a Hex value into Fill in a function
Jan 21st, 2009, 10:06pm
 
Hi there

Just a quick one, which I cannot fathom. I have a function which creates an object (an ellipse) and I want to pass in the fill value as a hex. How do I do this, I have tried passing in a string and then performing Integer.parseInt(string, 16) and passing in a char[] of the hex value but to no avail.

This is my code:


public circle(int x, int y, int d, char[] c)

{
      this.colour = new char[6];
      this.xpos = x;
      this.ypos = y;
      this.dimension = d;
      this.colour = c;
}

With the function being:


public void display()

{
    noStroke();
    smooth();
    fill(colour);
ellipse(this.xpos,this.ypos,this.dimension,this.dimension);

}

Sorry if this is documented, I have checked the documentation and investigated how to handle this with Java but I cannot see how to do it.
Re: Passing a Hex value into Fill in a function
Reply #1 - Jan 21st, 2009, 11:29pm
 
unhex() reference shows precisely this case in the example...
Don't forget to set alpha to FF, or at least something not null, otherwise the color will be totally transparent, ie. invisible!
Re: Passing a Hex value into Fill in a function
Reply #2 - Jan 22nd, 2009, 9:44pm
 
Perfect, thank you PhiLho. That is what I was looking for.

Now, I have a second question. I am struggling with colorMode. If I pass in the value of "FF3333" this equates to 16777011 as an int (which is cool). However, I don't get the warm red I would expect I get a grey color.

I have set (under void setup()) the colorMode(RGB,16777215); (I have previously set colorMode(RGB,255).

I am struggling to understand why I can't get colors via integers? I am setting the fill value in a method belonging to a class which is instantiated in void setup().  I think I am missing something quite fundamental with colorMode?

The method is:


public void display()

{


noStroke();


smooth();
println("Colour = "+this.colour);
               int c = unhex(this.colour);
println("C = "+c);
               fill(c);
               //fill(#FF3333);


ellipse(this.xpos,this.ypos,this.dimension,this.dimension);

}

P.s. If I use fill(#FF3333) I get the warm color I want with colorMode(RGB,255);
Re: Passing a Hex value into Fill in a function
Reply #3 - Jan 23rd, 2009, 8:45pm
 
I am not sure to get everything you mean.

But I believe colorMode() acts only on next calls to "fill(), stroke(), background(), and color()". Hex data and Web color notation are unaffected by the mode and remain RGB(255).
Page Index Toggle Pages: 1