We want to find an equation representing the equation on the left. We can begin with the operator modulo, represented by %. a%b gives the remainder when you divide a by b. For example, 7%3=1. x%1 – x%2 will give us -1 when x rounds down to an event number and 0 when it doesn’t. Add 0.5 and multiply by twice x%1 to get disconnected ups and downs centered at 0. If we add (x%1 – x%2) * -1 to this, we move up only the negatively sloped lines and get a zig-zag with peaks at 0 and 1. Add 2 to get our answer, the equation below.
y=2(x\%1-x\%2+0.5)(x\%1-0.5)+2.5