I need to perform a task using a math function (i'm a programer not a mathematician unfortunately).

The task i need to perform is to cycle through a list in a sinusoidal motion according to an increasing count.

the count (time) is increasing at a fixed rate, no problems there, however, I need the number of items in the cycle to change.

For example I have a 3 item cycle, 1->2->3->2->1->2 etc

I have managed to write an equation that will give me the result I need for this case:

So if t = x, number of items = 3:

Code:

t0 = 1,
t1 = 2,
t2 = 3,
t3 = 2,
t4 = 1

(with rounding of the result)

However, I may need to vary the number of items in the cycle to any arbitrary number, and as such would need for example the following to be true:

8 items:

Code:

t0 = 1,
t1 = 2,
t2 = 3,
t3 = 4,
t4 = 5,
t6 = 7,
t7 = 8,
t8 = 7,
t9 = 6,
t10 = 5,
...
t of 14 = 1

how would I modify the equation to take into account the number of items in the cycle? (If at all possible)

Thanks