Hopefully Monster doesn’t post before I do.
First of all, you need to know what value is your control variable and which value is dependent on this variable.
Let’s say x is our control variable and y’s value is dependent on x’s value.
We want to make it so that when x = 10, y = 5.
Simply put,
x = Any Number, y = x/2
What ever value x is, we divide it by 2 and we get the y value for it.
x = 1, y = 0.5
x = 5, y = 2.5
x = 6, y = 3
etc
etc
What Monster is doing is setting a range to calculate percentage.
x_min = 0 #Minimum value for x is 0
x_max = 10 #Maximum value for x is 10
Thus,
x_range = x_max - x_min
Sometimes the minimum isn’t zero like it is with your situation,
x_min = 10
x_max = 20
The range isn’t from 0 to 20, it’s from 10 - 20 which is 10.
Can you guess what it is for y?
y_min = 0
y_max = 5
y_range = y_max - y_min
Now we need to know the percentage of each of the values. How much of the variable is filled.
For example, we know that since the range between, 0 and 2 is 2, 1 would mean that 50% of this range is filled. Right?
0 is the minimum, 2 is the maximum.
2 is the range (2-0)
1 is the value
0.5 is the percent: 1(value) divided by 2(range)
So far we have the range, and now we need the value. Since x has a value that we set, the only value we don’t know is y.
So we know,
x_value = (any number we set)
y_value = (affected by number set to x)
Now we have:
x_value/(x_range)
y_value/(y_range)
But aren’t we missing something? What if the minimum of x and y were not 0 and instead 5? The equation would fail. Think about it for a bit and you’ll understand why.
A = (x_value-x_min)/x_range
B = (y_value-y_min)/y_range
These percentages must be the same, why? Because when x is half filled, you want y to be half filled. Therefore y is proportionate to x.
And,
A = B
Remember, we still don’t have the value for y, but we have everything else. With basic algebra you arrange it so the y_value is what we are solving for.
Finally,
y_value = y_min + (x_value-x-min)/(x_range)*y_range
This is actually how we get x = # and y = x/2
y_value = 0 + (#-0)/10*5