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 › setValue ControlP5
Page Index Toggle Pages: 1
setValue ControlP5 (Read 756 times)
setValue ControlP5
Nov 24th, 2009, 8:26am
 
Hi,

I would to use librairy controlP5 to change the position of an ellipse, but as easy as it may be, I don't reach to... I don't reach to give the value to the parameters of this ellipse...

Someone can check if my syntax is correct please?

Code:

import controlP5.*;
ControlP5 controlP5;

float posX = 50;

void setup(){
 size(250,150);
 noStroke();
 smooth();

 controlP5 = new ControlP5(this);
 String[] parametres = new String[1];

 controlP5.addSlider("position",50,150,50,30,100,150,10);
}



void draw(){
 background(180);
 fill(255,0,0);
 ellipse(posX,50,10,10);
}

void slider(float posX) {
 controlP5.controller("position").setValue(posX);
}
Re: setValue ControlP5
Reply #1 - Nov 24th, 2009, 9:02am
 
In the following line:

Code:
controlP5.addSlider("position",50,150,50,30,100,150,10); 



"position" is the name of the function called from the slider; so you need to write a corresponding function (i.e. not slider()) that takes one argument: the value returned by the slider.  In this function you can assign the value of the slider to your global variable:

Code:
void position(float p) {
 posX = p;
}


... at least that's how I did it the last time I worked with p5; and it works with your code Wink
Re: setValue ControlP5
Reply #2 - Nov 24th, 2009, 9:04am
 
perfect !
thank you very much
Page Index Toggle Pages: 1