Don't moveTo()
after each lineTo()
In other words, remove every moveTo()
except the first one.
Seriously, if I just copy-paste OP's code and remove the unnecessary moveTo()
calls, it works.
Nothing else needs to be done.
EDIT: I know the OP already posted his "final working solution", but he didn't state why it works. The actual reason was quite surprising to me, so I felt the need to add an answer.