You can increase or decrease the number of balls on screen using the UP and DOWN arrows respectively.
The source is here: https://github.com/dreasgrech/balls
Some implementation details
The backgroundTo implement the colorful background, I'm using a cylindrical-coordinate representation of the RGB color model, known as HSV (Hue Saturation Value). Keeping the saturation and value to a constant 100 (max), I'm iterating through values 0-360 for the hue thus achieving the blending of colors. When the hue reaches 360, I reset it back to 0 and the cycle starts over.
The initial value of the hue is randomly chosen at the beginning.
BallsAll of the balls' attributes are randomly generated i.e. the initial position, size, color, speed and angle.
Since collision detection is only applied once the balls hit the edges of the browser window and the edges are axes aligned, I'm simply inverting the part of the velocity's depending to which edge is hit.
If the ball hits either the left or right edge, the x is inverted and if the ball hits the top or bottom edge, the y is inverted.