Equation to a custon slider

0 favourites
  • 7 posts
From the Asset Store
Photo Slider Puzzle with unlimited no of grids & pieces
  • I'm making a custum slider.

    I have two numbers...

    Min = 120

    Max = 400

    I want:

    120 = 0%

    400 = 100%

    I don't know the equation for this.

    I want create a percentage to a custom range... How do i do it?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Subtract 120, so the range is 0 to 280. 280 is your divisor, so the coordinate X, minus 120 divided by 280 is the factor (0 to 1). Or, the factor multiplied by 280 plus 120 gives you X. (Remember, you don't actually work in percentages. You want a factor from 0 to 1, where the percentage is just the factor times 100).

  • Subtract 120, so the range is 0 to 280. 280 is your divisor, so the coordinate X, minus 120 divided by 280 is the factor (0 to 1). Or, the factor multiplied by 280 plus 120 gives you X. (Remember, you don't actually work in percentages. You want a factor from 0 to 1, where the percentage is just the factor times 100).

    Humm cool. i will use, but when i want:

    -100 = 0%

    0 = 100%

    what do i do?

  • You always want a number between 0 and 1, and 0 to be the starting point, so add 100. That gives you 0 to 100. Divide by 100 to get the factor (0to1). Do your math, multiply by 100, then subtract 100 again, to move everything back into range.

  • woah what complications, how about this:

    x = Min + (random() * ((Max - Min) + 1))

    1st problem = minimum is 280, maximum 420.

    same thing applies to the 2nd problem, your minimum is -100, while your maximum is 0.

    same formula applies. - gives you a random number between your max and min, now if you want percentage of that number in your range you just apply this:

    perc = (x /(max+min))*100

  • You always want a number between 0 and 1, and 0 to be the starting point, so add 100. That gives you 0 to 100. Divide by 100 to get the factor (0to1). Do your math, multiply by 100, then subtract 100 again, to move everything back into range.

    Thanks

  • woah what complications, how about this:

    x = Min + (random() * ((Max - Min) + 1))

    1st problem = minimum is 280, maximum 420.

    same thing applies to the 2nd problem, your minimum is -100, while your maximum is 0.

    same formula applies. - gives you a random number between your max and min, now if you want percentage of that number in your range you just apply this:

    perc = (x /(max+min))*100

    Hey, perfect! Thank you!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)