Update Variable Only When Running
in
Programming Questions
•
5 months ago
Hi all.
I hope this will make some sense, but I am wondering about this, and I can't understand how Processing works, maybe someone will be able to clarify this for me.
So, for example, in the following code, I increase the fade value until it reaches a specific limit.
int fade = 0;
void setup(){
size (400,400);
}
void draw(){
fade++;
fade = constrain(fade, 0, 255);
println (fade);
}
How can I stop the program from constantly updating this value? So, if I print the value I will be receiving per every frame the same value, however I want to make sure that this stop.
Giving another example, if I use the controlP5 slider, you may notice that the value of the slider is printed only when the value changes, and not constantly. Therefore I would like to be able to control in the same manner the value in the first example.
- import controlP5.*;
- ControlP5 cp5;
- int newValue;
- void setup() {
- size(640, 250);
- noStroke();
- frameRate(30);
- cp5 = new ControlP5(this);
- cp5.addSlider("slider").setPosition(20, 100).setSize(150, 20).setRange(0, 255).setValue(255);
- }
- void draw() {
- background(80);
- }
- void slider (int theSlider) {
- newValue = theSlider;
- println(newValue);
- }
1