define('ball', [
    'c',
    'vector2'
], function (
    C,
    Vector2
) {
    'use strict';
    return function (pX, pY, pRadius) {
        var canvas = C.canvas,
            ctx = C.ctx,
            radius = pRadius ? pRadius : Math.floor(Math.random() * 11) + 15,
            pos = new Vector2(
                pX ? pX : Math.floor(Math.random() * (C.canvasWidth - radius - radius)) + radius,
                pY ? pY : Math.floor(Math.random() * (C.canvasHeight - radius - radius)) + radius
            ),
            oldPos = pos.clone(),
            velocity = new Vector2(0, 0),
            gravity = new Vector2(0, 0.5),
            gravityOn = true,
            twoPi = Math.PI + Math.PI,
            color = 'rgba(' +
            Math.floor(Math.random() * 256) + ',' +
            Math.floor(Math.random() * 256) + ',' +
            Math.floor(Math.random() * 256) + ',0.5)',
            velocityBounce = function () {
                var nx,
                    ny;
                if (pos.x <= radius || pos.x >= C.canvasWidth - radius)
                    nx = velocity.mirror(true).x;
                else
                    nx = pos.x - oldPos.x;

                if (pos.y <= radius || pos.y >= C.canvasHeight - radius)
                    ny = velocity.mirror(false).y;
                else
                    ny = pos.y - oldPos.y;

                return new Vector2(nx, ny);
            },
            move = function () {
                velocity = velocityBounce();
                if (gravityOn)
                    velocity = velocity.add(gravity);
                oldPos = pos.clone();
                pos = pos.add(velocity);
                pos = pos.clip(radius, radius, C.canvasWidth - radius - radius,
                    C.canvasHeight - radius - radius);
            },
            ball = {
                init: function () {

                },
                update: function () {
                    move();
                },
                draw: function () {
                    ctx.beginPath();
                    ctx.arc(pos.x, pos.y, radius, 0, twoPi);
                    ctx.fillStyle = color;
                    ctx.fill();
                }
            };

        return ball;
    };
});
@@ -116,16 +116,27 @@
 (pX, pY,
+ pVelocity,
  pRadius
@@ -135,24 +135,24 @@
  pRadius) %7B%0A
-
         var 
@@ -576,48 +576,20 @@
 y = 
-new Vector2(0, 0),%0A            grav
+pVeloc
 ity 
-=
+%7C%7C
  new
@@ -601,18 +601,16 @@
 or2(0, 0
-.5
 ),%0A     
@@ -627,17 +627,8 @@
 vity
-On = true
 ,%0A  
@@ -865,30 +865,30 @@
         
-v
+getNewV
 elocity
-Bounce
  = funct
@@ -944,16 +944,90 @@
     ny;%0A
+                // Reverse ball x-direction if it's heading out of screen%0A
         
@@ -1204,17 +1204,56 @@
 dPos.x;%0A
+                // Idem for y-direction
 %0A
-
         
@@ -1556,22 +1556,22 @@
 y = 
-v
+getNewV
 elocity
-Bounce
 ();%0A
@@ -1601,11 +1601,41 @@
 vity
-On)
+) //Check if gravity is turned on
 %0A   
@@ -1681,24 +1681,25 @@
 d(gravity);%0A
+%0A
             
@@ -1761,24 +1761,84 @@
 (velocity);%0A
+                //Prevents balls from falling through floor%0A
             
@@ -2032,17 +2032,104 @@
 on () %7B%0A
+                    this.setGravity(0.25);%0A                    pos = pos.add(velocity);
 %0A
-
         
@@ -2429,24 +2429,443 @@
 ctx.fill();%0A
+                %7D,%0A                /**%0A                 * Sets new gravity. If parameter is left empty, gravity is turned off.%0A                 * @param %7BVector2%7D value - How much gravity should be.%0A                 */%0A                setGravity: function (value) %7B%0A                    if (value)%0A                        gravity = new Vector2(0, value);%0A                    else%0A                        gravity = null;%0A
             
@@ -2870,16 +2870,16 @@
       %7D%0A
+
         
@@ -2885,17 +2885,16 @@
      %7D;%0A
-%0A
         

add gravity toggling and possibility for starting velocity