I am making a basic 2D rigid body simulator as a hobby. It involves springs. Naturally, I need to render them. Rigid body simulators, such as Algodoo, render them simply like this

Another (more common) helical representation

And many more...
So, to render these, I need some periodic function (with amplitude of $A$) which takes the number of turns $t$ (The number of turns is the same as the number of periods in the wave. E.g $\sin(x)$ contains $1$ turn in $[0,2\pi]$), and has the starting and end point $(x_1,y_1)$ and $(x_2,y_2)$ respectively. The end point and the starting point must be at "mean" position of the amplitude. (E.g $f(x)=0$ in $f(x)=\sin(x)$)
Any helical or triangle-wave like (or perhaps some other representation?) function will do. I don't know how to approach this.
I don't have access to built in functions for triangle waves, et cetera. Any suggestions?
Thank you.

The basic problem is to obtain the parametric representation of the projected spring $\gamma$ in your second figure, connecting the points $(0,0)$ and $(1,0)$. Apart from the $y$-amplitude $A>0$ we can choose the number $2n+1$ of half-waves and a parameter $B>0$ which encapsulates the degree of selfintersection of $\gamma$. As a function of time, $\gamma$ is a superposition of a clockwise elliptical motion $$t\mapsto\bigl(x_e(t),y_e(t)\bigr):=(A\sin t,-B\cos t)\qquad\bigl(0\leq t\leq(2n+1)\pi\bigr)$$ and a linear motion in $x$-direction, described by $$t\mapsto x(t):=a+ bt\ ,$$ where $a$ and $b$ have to be chosen suitably. Therefore the parametric representation of $\gamma$ looks as follows: $$\gamma:\quad t\mapsto\left\{\eqalign{x(t)&:=a+bt-B\cos t \cr y(t)&:=A\sin t\cr}\right.\qquad\bigl(0\leq t\leq (2n+1)\pi\bigr)\ .\tag{1}$$ The condition $x(0)=0$ gives $a=-B$, and $$1=x\bigl((2n+1)\pi\bigr)=2B+(2n+1)\pi b$$ leads to $$b={1-2B\over (2n+1)\pi}\ .$$ In this way the representation $(1)$ becomes $$\gamma:\quad t\mapsto\left\{\eqalign{x(t)&:=B(1-\cos t)+{1-2B\over (2n+1)\pi}\>t\cr y(t)&:=A\sin t\cr}\right.\qquad\bigl(0\leq t\leq (2n+1)\pi\bigr)\ .$$ The reasonable condition $x(2\pi)>0$ implies $0<B<{1\over2}$. The following figure shows the resulting $\gamma$ when $n=6$, $A=0.2$, and $\>B=0.11$:
Now we have to transform $\gamma$ into a spring with given endpoints $(x_0,y_0)$, $\>(x_1,y_1)$. Let $$d:=\sqrt{(x_1-x_0)^2+(y_1-y_0)^2},\qquad\phi:=\arg(x_1-x_0,y_1-y_0)\ .$$ Then the coordinates of the transformed point $(\bar x,\bar y)$ are obtained from $(x,y)$ by the operation $$\left[\matrix{\bar x\cr \bar y\cr}\right]=\left[\matrix{x_0\cr y_0\cr}\right]+d\ \left[\matrix{\cos\phi&-\sin\phi \cr \sin\phi&\cos\phi\cr}\right]\>\left[\matrix{x\cr y\cr}\right]\ .$$