Watch the balls bounce on each other. To change the number of balls, you have to click the flag again. It follows the law of conservation of momentum, and the conservation of energy. All the balls are the same mass. To see the calculated momentum and energy, press space. Watching the numbers is boring because they don't change much; but that just means it's working how it should.
I was looking through my old projects and decided to fix this one. Version 2: https://scratch.mit.edu/projects/661509314/ Version 3: https://scratch.mit.edu/projects/662160288/