Check it out here.
This is a snippet of the loop, the important part.
function loop() {
updatePosition();
// Draw over the whole canvas to create the trail effect
context.fillStyle = 'rgba(255, 255, 255, .05)';
context.fillRect(0, 0, canvas.width, canvas.height);
// Draw the dot
context.beginPath();
context.fillStyle = '#ff0000';
context.moveTo(dot.x, dot.y);
context.arc(dot.x, dot.y, 3, 0, Math.PI*2, true);
context.fill();
}
