The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

1. 73
posts
Registered User

slider with numbers

So i got the slider itself working, but how would I, for example with a slider length of 1 to 100 pixels create an array of numbers between 20 and 200? (or simply between numbers x and y)?

I figure theres tutorials all over the web for a formula, and that theres even a simple 9th grade math equation for it, but im simply too lazy.

Thanks in advance for any help..

2. Originally Posted by GeekTweak.0
I figure theres tutorials all over the web for a formula, and that theres even a simple 9th grade math equation for it, but im simply too lazy.
Well I was going to just give you the equation until I read that It is a very simple problem: you want a linear function that maps 1->20 and 100->200. That's enough data to solve the equation y=mx+b.

3. 73
posts
Registered User
alright, so maybe im just a moron, but i am having trouble and learn much better through visual example. from x values of the slider being between 10 to 100, and desired output being between 20 to 200, and variable:value is the output depending on slider.x(that x value being between 10 and 100).... what equation do i plug in to get value?? Maybe just cuz i aint been in school for a while, maybe cuz im tired, maybe both, idk. please just give me the answer XP

4. Oh the input value is from 10 to 200? That makes it even easier. You really can't figure out how to scale the interval 10-100 to 20-200?

Here's a visual example: Tommy has 10 apples. Sally has 20 apples. How many times more apples does Sally have than Tommy?

5. 221
posts
Carebear
Usually i make the sliders to return Number from 0 to 1 and then transform it to any value needed. Simple percentage usage. I that case the transformation will look something like this:

value = minValue + (Math.abs(maxValue - minValue)*sliderPercent);

in your 20 to 200 case:
value = 20 + (Math.abs(200-20)*sliderPercent);

Props to The Canadian for the visual aids

6. I knew someone was just going to give it to him eventually. Although, if your input is 10-100, there is a much simpler equation to use. Perhaps there's some constant you can multiply it by…

7. 221
posts
Carebear
Although, if your input is 10-100, there is a much simpler equation to use. Perhaps there's some constant you can multiply it by…
I wonder what that constant might be ...

8. I'm sure there's enough leading questions in this thread to figure it out

9. 73
posts
Registered User
yes thank you everyone. the answer was very simple. I needed the formula because the min-max values and variables would be different for each slider i make. thanks.

10. I gave you the formula in the second post