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 serious problem with slider precision
Page Index Toggle Pages: 1
controlP5 serious problem with slider precision (Read 338 times)
controlP5 serious problem with slider precision
Jan 25th, 2009, 5:46am
 
After some mysterious behavior appeared in a project I've been working on, I finally figured out that controlP5 slider methods can give slightly inaccurate numbers!  The issue appears to be in sliders only, as far as i can tell - a non-constraint of decimal places when dividing control location by the width of the control.  

The code below illustrates the problem, the value is set to 2.00 and auto-initialization prints the value immediately to the p5 text window.  The value is exactly 2.0 as you would expect.  But set the control to 2.00 with the mouse and the value becomes 2.0066667, and you can't get it to exactly 2.0!  At different pixel widths of controls this doesn't happen, as well as different ranges of minimum-maximum, again because it depends on non-rounded result of mathematical division.  But it's a real problem if you enlarge a control, or change its max, and all of a sudden you're getting different numbers without knowing it.  

It seems to me there needs to be a controller method to set desired places of decimal precision, or even better, a way to set how you want values incremented (e.g. by 0.1, 0.05, etc), so they would neatly snap.  Of course this can be fixed easily with rounding in the controller function, but...

Code:

import controlP5.*;

ControlP5 controlP5;
float F = 2.0;

void setup() {
size(400,200, JAVA2D);

controlP5 = new ControlP5(this);
controlP5.setAutoInitialization(true);

controlP5.addSlider("Test", 0, 7, F, 20, 20,150,15);
}

void draw() {
background(0);
}

void Test(float _F) {
println(_F);
}
Re: controlP5 serious problem with slider precisio
Reply #1 - Jan 28th, 2009, 5:17pm
 
With version 0.3.9 there will be an option to set the decimal points for controllers. I will also look into the snap option you suggested.
Re: controlP5 serious problem with slider precisio
Reply #2 - Jan 28th, 2009, 5:40pm
 
that's great.  any guess as to when that will come out?  

i appreciate all your work on this free library, and i'm sure the whole p5 community does too.

- eric
Re: controlP5 serious problem with slider precisio
Reply #3 - Jan 29th, 2009, 1:02pm
 
thanks eric. i just did update to 0.3.9.
Page Index Toggle Pages: 1