Dragon Curve algorithm in JS