When I click my button in the following code, a linear animation occurs for a circle. How can I get it to where that original circle keeps moving on its path and start a new animation along the same path with another circle, I would like to be able to do this multiple times, sometimes I may have 10 on there or so.
Currently when I click the button multiple times it either starts from the beginning of the canvas or pulsates between two animating circles.
$('#dSubmit').click(function(){
var ctx;
var x = 15;
var y = 50;
var dx = 1;
var dy = 0;
var WIDTH;
var HEIGHT;
function init() {
ctx = $('#canvas')[0].getContext("2d");
WIDTH = $("#canvas").width();
HEIGHT = $("#canvas").height();
return setInterval(draw, 10);
}
function circle(x,y,r) {
ctx.fillStyle = "#81cbf2";
ctx.beginPath();
ctx.arc(x, y, r, 0, Math.PI*2, true);
ctx.closePath();
ctx.fill();
}
function rect(x,y,w,h) {
ctx.beginPath();
ctx.rect(x,y,w,h);
ctx.closePath();
ctx.fill();
}
function clear() {
ctx.clearRect(0, 0, WIDTH, HEIGHT);
}
function draw() {
clear();
circle(x, y, 10);
x += dx;
y += dy;
}
init();
});