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 & HelpOther Libraries › ControlP5 - color as color() & not as int()
Page Index Toggle Pages: 1
ControlP5 - color as color() & not as int() (Read 1554 times)
ControlP5 - color as color() & not as int()
Jul 2nd, 2009, 9:49am
 
Greetings

I'm quite new to processing and ran into trouble with using the ControlP5 library.
I'm still in the state of experimenting and tried to change the controlP5-basic example.

I wanted to make a toggle-button that changes the transparency of every element. Including the button.

Code:
import controlP5.*;

ControlP5 controlP5;

int visOpaque = 255;
int ColorSquare = 200;
int ColorRect = 0;
int ColorBackground = 100;
int ColorToggle = color(253,228,55, visOpaque);
int ColorActive = color(244,249,250);
boolean globalTrans = false;


void setup() {
 size(400,200);
 frameRate(25);
 controlP5 = new ControlP5(this);
 controlP5.addToggle("toggleGlobalTrans",true,10,10,40,40).setColorActive(ColorActive);
}

void draw() {
 background(ColorBackground);
 fill(ColorSquare);
 rect(200,50,100,100);
 fill(ColorRect,visOpaque);
 rect(0,0,width,100);
}

void toggleGlobalTrans(boolean globalTrans) {
 if(globalTrans==false) {
   visOpaque = 200;
   controlP5.setColorForeground(ColorToggle); //<--- ???
 } else {
   visOpaque = 255;
   controlP5.setColorForeground(ColorToggle);
 }
}


But I don't know how to give the changed color-value to the controlP5-controller because it needs integer-values.

I hope I could discribe the problem so you get what I mean & of course that the question is not that stupid.

As I said I'm a real beginner   Wink
Re: ControlP5 - color as color() & not as int()
Reply #1 - Jul 2nd, 2009, 2:54pm
 
Maybe this is what you mean?
color() is an int already, well sort of.

Code:

void toggleGlobalTrans(boolean globalTrans) {
 if(globalTrans==false) {
   visOpaque = 200;
 } else {
   visOpaque = 255;
 }

 ColorToggle = color(253,228,55, visOpaque);
 controlP5.setColorForeground(ColorToggle); //<--- ???
}
Re: ControlP5 - color as color() & not as int()
Reply #2 - Jul 2nd, 2009, 4:46pm
 
Thank you. That's what I meant.
Wasn't that difficult. Now I feel kind of stupid asking such a simple thing.
The color() int() thing is confusing to me.
println() says colorBlu = -16755201 after the color is transformed to integer, right?
But nevertheless I'm one step closer to the goal. And I think it's gonna be fun.

Thx again
Re: ControlP5 - color as color() & not as int()
Reply #3 - Jul 2nd, 2009, 5:19pm
 
Is it possible to save the previous color of every individual element and to just change the alpha value?. So that the color value stays untouched.
Re: ControlP5 - color as color() & not as int()
Reply #4 - Jul 3rd, 2009, 3:23am
 
actually your question is not trivial at all, since color is its own datatype. To see how it works, you can look in the reference here: http://processing.org/reference/color_datatype.html
As for your second question, of course you can, among a million other things. At this stage, I would suggest you switch off the computer, take pencil and paper, and draw a flowchart of what your programm will be doing. You will see it all becomes clear. Also a good book to get you started and more, is "Processing: A Programming Handbook for Visual Designers and Artists". It's on the processing homepage, the book with the blue cover. I enjoy it a lot.
Page Index Toggle Pages: 1