The balls bounce like billard balls (or like gas molecules). The calculations for an elastic collision are harder than my previous examples - I won't explain them completely in there. If you want the detail, look at the script comments and follow up more information on the science - you could try the article "elastic collision" on wikipedia. Enjoy scrathing!