The above simulation was not created with EJS. It was created more than 10 years ago with JDK1.0.2.
The coordinate of center of mass Xcm=(m1*X1+m2*X2)/(m1+m2)=(m1*X1+m2*X2)/mcm;
So mcm=m1+m2 is the sum of those two particles.
It is defined to make calculate property in the center of mass system much easier.
The radius of two circles are R1 and R2, the distance between two center of the curcle d=|x2-x1|,
if d < R1+R2 then we know the circles should have collided with each other when d=R1+R2;
So we need to move time backward with ddt=(R1+R2-d)/|V2-V1|.
This is moment those two circle collide with each other.
Then, use the formula shown at the first message (or check out standard physics textbook) to calculate velocity for each circle. (V1', V2')
Then move the time forward to t: