You can simply use traditional trig functions to create a triangle-wave as a function of x
import math triangle_function = lambda x: math.asin(math.sin(2*math.pi*x))