How to fix this bug(canvas)?

Good evening.
There is a draft.
Sometimes comes such a bug:
2a9193d704aa4e22ace3d05684f42e79.png

The files here.
June 26th 19 at 14:00
1 answer
June 26th 19 at 14:02
Solution
replace line 31 in
ctx.clearRect(-width , -height , 2*width, 2*height);

Find more questions by tags CanvasJavaScript