The kinetic energy $(K)$ and the potential energy $(U)$ in terms of displacement $(x)$ are derived from the equation for the velocity in terms of displacement ($v=\pm\sqrt{x_{0}^{2}-x^{2}}$). This is given by:\begin{align*}E_{\text{k}}&= \frac{1}{2}mv^{2}\\&=\frac{1}{2}m\omega^{2}(x_{0}^{2}-x^{2})\\E_{\text{p}}&=E_{\text{T}}- E_{\text{k}}\\&=\frac{1}{2}m\omega^{2}x^{2}\end{align*}
Note that both energies are positive since $x$ is always smaller than $x_{0}$.
$m=$mass of the object; $x_{0}=$maximum displacement; $\omega=$angular frequency.