Number rising and falling

basically i want a number to go up until the middle of a for loop then the number goes down

for i = 1, n do
	-- example: n = 8
	-- from n = 1 to n <= 4 f(i) starts at 0 then goes up to m
	-- from n > 4 to n = 8 f(i) starts at m then goes down to 0
end

the end result i want should look like this graph

you already have the pseudocode written out so you could write an if statement where the value is equal to i when i <= n/2 but equal to n-i when i >= n/2

you could also do it with a formula with -1 * math.abs(i-n/2) + n/2

confirmed it works

loop starts at 1 tho

(n-1)/2 - math.abs(i - (n-1)/2 - 1)

almost what i want, but i want the max value to be controllable
aka max of f(i) is m

also keeping it just 1 equation is preferable

-1 * Math.abs(2*m/n*(i-1-n/2)) + m

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.