Your real problem is you are not closing your circle’s path.
Add ctx.beginPath()
before you draw the circle.
Also, some tips…
- Your assets should not be responsible for drawing themselves (their
draw()
method). Instead, perhaps define their visual properties (is it a circle? radius?) and let your main render function handlecanvas
specific drawing (this also has the advantage that you can switch your renderer to regular DOM elements or WebGL further down the track easily). - Instead of
setInterval()
, userequestAnimationFrame()
. Support is not that great at the moment so you may want to shim its functionality withsetInterval()
or the recursivesetTimeout()
pattern. - Your
clearRect()
should be passed the dimensions from thecanvas
element (or have them defined somewhere). Including them in your rendering functions is akin to magic numbers and could lead to a maintenance issue further down the track.