# Math question

I am just quite braindead at the moment. So I need your help with some math magic I have a counter counting up like this

``````for x in range(5):
do something at position x
``````

Variable x will have values 0, 1, 2, 3, 4. My something will wander from left to right (ok just only 5 pixel, but this is only for the example)
Now I want a knob that makes this movement smaller and smaller and finally inverts the movement. If I assume five positions of the knob, then I will get the following matrix (please ignore, that in reality positions can not be expressed in fractions):

``````knob |resulting position at
value|x=1 x=2 x=3 x=4 x=5
-----+--------------------
0.0  |0.0 1.0 2.0 3.0 4.0
0.25 |1.0 1.5 2.0 2.5 3.0
0.5  |2.0 2.0 2.0 2.0 2.0
0.75 |3.0 2.5 2.0 1.5 1.0
1.0  |4.0 3.0 2.0 1.0 0.0
``````

How do I come from the knob position to the increasing inversion of the values?
I am sorry, but somehow my brain is blocked completely at the moment.

this?

``````step = (knob * 2 - 1) * -1  #step goes from 1 to -1
start = knob * 4
pos = start + x * step``````

Hi

Thanks for your tip. It did not make it completely, but the idea to shift the range of values from “0 to n” to “-n/2 to +n/2” was the essential hint. This one does it:

``````    maxrange=<ENTER YOUR VALUE HERE>
for i in range(maxrange):
i-inv = ((i-(maxrange/2)) * ((etc.knob1 * 2) - 1)) + (maxrange/2)
xpos = int((640/maxrange) * i-inv)
``````

The “640” is in this case the half width of the screen.