-2
$\begingroup$

Let's say I want to move a shape with coordinates.

The end position is: -500 pixels. The start position is: 500 pixels.

Using a slider with a range of 1-100, I want to move the shape between the start and end position using percentage. When this percent value changes, I want to move the shape. 100% would place the shape at the end position, 0% would place the shape at the start position. Any percentage between would set the pixel value accordingly.

Letters below are variables.

A: -500

B: 500

C: Percentage value between (1-100).

D: (ANSWER)

I need a new value (D) to be the percentage value (C) between (A) & (B).

So if (C) was 50 - (D) would be value 0.

50% between A and B is 0.
  • 0
    Your question is not enough clear. Please explain it properly2017-01-23
  • 0
    I've added the example above.2017-01-23

2 Answers 2

0

I think you are looking for $$ D = A + (B-A)\cdot \frac{C}{100} $$ or, with your particular $A$ and $B$ inserted, $$ D = 10\cdot C - 500 $$

  • 0
    Sorry trying to figure out how this formula works with the decimal point?2017-01-23
  • 0
    @SMKS_ARTS: Which decimal point? If your $C$ is not an integer, just plug it into the formula, fractional part and all. (You're not mistaking the multiplication signs for decimal points, are you?)2017-01-23
  • 0
    In programming terms I have this: var a = -500, b = 500, c = 50; var d = a = (b - a) / 100)2017-01-23
  • 0
    I read your formula as this: (a + (b - a)) * (50 / 100)2017-01-23
  • 0
    @SMKS_ARTS: No, the multiplication binds tighter than the addition!2017-01-23
  • 0
    I see. I have: a + ((b - a) * 50 / 100)2017-01-23
0

Given two numbers $\alpha $ and $\beta $, a percentage change of $\gamma $ gives the position as $\delta =\alpha +\frac {\beta-\alpha}{100}\gamma $. Try using this result with $\alpha=-500$ and $\beta=500$. Hope it helps.

  • 0
    Why the Greek letters? That seems to be likely to confuse the OP for absolutely no gain that I can see.2017-01-23
  • 0
    Sorry, @HenningMackholm I did not load your answer while writing mine and then I saw that we have both given the answer along the same lines. Sorry again.2017-01-23