Upward Dots

I made a fairly simple project today that involved taking yesterdays experiment and making some of the dots go up. I wanted the dots to originate from above, but then go up after a click. The program is fairly slow, so I might try to think of a better algorithm if I ever turn this into a game. I successfully added an event listener to capture any clicks, and found a bit of code to offset the positions.

The additions to the code were fairly simple, but I also had to update the removal process to get rid of the circles that moved above the canvas element.

switchDir : function(event) {
    var xPos = canvas.relMouseCoords(event)['x'];
    var yPos = canvas.relMouseCoords(event)['y'];
    for (i=0;i<objects.number;i++) {
        if (Math.abs(objects.centers[i][0]-xPos) < 30 && 
            Math.abs(objects.centers[i][1]-yPos) <30) {
            objects.stepSize[i] = -1*objects.stepSize[i];
        }
    }
}

The number of circles redirected by each click can easily be varied by changing the range on that if statement. 30 pixels appeared to work well on my machine to create some interesting patterns. The code can be found here and below.