ControlP5 Slider with integer ticks

edited February 2016 in Library Questions

Hi guys,

Is there anyway to make the tick amount integers? I have set the slider's min to 0 and max to 599. I then set the number of ticks to be 600. However, whenever it iterates it goes: 0, 1, 2, 3, 4, 5, 5.99, 7, 8, 9.99, 11, 12.000002, 13, instead of just integers. The 5.99 instead of 6 and 9.99 instead of 10 really throws off my animation. Same goes for the 12.0002. Is there anyway to combat this?

Thanks

Answers

  • edited February 2016

    Can't you just round() those values when reading from them?
    https://Processing.org/reference/round_.html

  • Yeah I round them before i pass them into func(int val). But inside my function I want to do slider.setValue(val). Each time the draw function gets called this would move the slider's handle forward. But when i get to 6, I can't set the slider's value to that because the slider only contains 5.99. Do you know any ways I could set the slider's Value or animate it in this manner?

  • edited February 2016

    Sorry I'm not that familiar w/ this library.
    And I wouldn't that much about the internal value since we can always round() it.

  • Okay thanks though. The round() works for the value i grab from the slider to work with in my function. I just can't set it back to the slider since it won't match the slider's tick.

  • I'm ignorant about the library but, why would you want to setValue() back to the Slider?
    Wasn't it supposed to be the user to do it? :-??

  • Yeah each tick mark of the slider is part of my animation. So if the user moves the slider forward my event will animate forward. If the user moves it backward it'll rewind the animation. But I also have a play button where it just plays through fully. I want the slider's handle to be moving too when the play button is pressed.

  • edited February 2016

    Well, so when dealing w/ that Button, just don't round() it, right?
    Something like slider.setValue(slider.getValue() + 1.0) me guess? :-?

  • edited February 2016

    Oh that almost got it. Thanks for all the help btw! I really appreciate it!

    So i have draw(){
    int val = round(slider.getValue());
    event(val);
    }

    event(int val){
    //do stuff with val
    slider.setValue(slider.setValue() + 1.0);
    }

    It breaks with 25. It becomes 26 but my slider has 25.9

    So the output after each iteration with line of code is :

    1.0 2.0 3.0 4.0 5.0 6.0000005 7.0 8.0 9.0 10.0 11.000001 12.0 13.0 13.999999 15.0 16.0 17.0 18.0 19.0 20.0 21.000002 22.0 23.0 23.999998 25.0 26.0 <-- dies here because slider only has 25.9

  • edited February 2016

    Please format your code for the forum, it's barely readable:
    https://forum.Processing.org/two/discussion/8045/how-to-format-code-and-text

    I don't get why would you need to invoke getValue() 2 times, 1 in draw() and another 1 in event()?

    About the 25.9 limit, you can use min() in order to constrain anything more than it back to 25.9: https://Processing.org/reference/min_.html

  • edited February 2016 Answer ✓

    Oops I'm sorry about the code formatting! The second getValue() was also a typo. I meant to do setValue(). How would the min work though? I wouldn't know that I have 25.9 because that's in the next iteration.

    If I remove the .SetNumberOfTickMarks(600) out of my code, then I will have all the numbers in my range. Removing this allows my code to work because all the integers will exist in the slider. However, the slider still displays the tickNumber on the slider. Do you know how to remove this? If i can remove this, then I can just use your round function when the user moves the bar to get the correct numbers.(without the user actually seeing the number on the bar)

    edit: so I did .setDecimalPrecision(0) which then makes the number show up to the users as integers. The actual numbers aren't integers, but then using the round() function will make the calculations still okay. woot!

  • edited February 2016

    It seems that Slider.getTriggerEvent() is doesn't quite work how I imaged. I thought it would get either Slider.PRESSED or Slider.RELEASE, which to me is when either the user is pressing the slider or no longer pressing. However, Pressing the slider never actually satisfies the Slider.PRESSED condition in an if statement.

    Edit: Had to use the isMousePressed() function that instead.

  • Answer ✓

    Well, so it seems it's all settled, right? :-j

  • edited February 2016

    How would the min() work though?

    slider.setValue( min(slider.setValue() + 1.0, 25.9) );
    It would make sure that 25.9 is the maximum resultant value always. :-B

  • Thanks for all the help GoToLoop! Wouldn't the min function require me to actually know the next value is 25.9 otherwise we'd be hardcoding it in?

  • edited February 2016

    I mentioned min() b/c you said the value 26 would break:
    "dies here because slider only has 25.9". Perhaps you wanted 25 instead.
    min() is just a mean to disallow something of getting bigger than a specified amount.
    For example min(100, 25) returns 25, b/c 25 is the lowest value, and consequently the max limit. Re-read min()'s reference:
    https://Processing.org/reference/min_.html

Sign In or Register to comment.