# Ping Pong Math node - what does it do?

Reading through the math node docs, I came across a math function named "ping-pong".

The docs state that ping-pong does the following

The output value is moved between 0.0 and the Scale based on the input value.

What in the world does that mean? Can anyone tell me what the actual ping-pong function is? What input values lead to an output of 0, and what input values lead to an output of "scale"?

It's a positive symmetrical triangle-wave, amplitude Scale, period 2 * Scale, 0 at 0.

Here's the function illustrated with 'Scale' (from the bottom up) set to 1, 0.5, and 0.333.

These planes are 8 units across, and 2 up, 0 at center.

You could roll your own like this:

PingPong(Value) = Scale - abs( (abs(Value) % (2*Scale)) - Scale)


..but someone else might come up with a neater way.. :)

You could wrap up the node like this to give more intuitive inputs?

• great illustrative answer, thank you. Glad I asked, because that's not at all what I imagined it would be. I expected a square-wave type function. – rothloup Jul 12 at 15:13
• @rothloup Thanks! .. Keep the graphing trick in your back pocket.. you can visualise the other functions, and your own combinations. – Robin Betts Jul 12 at 16:21