Each galaxy is a heavy softened core and an exponential disk of lighter stars. The stars are placed on circular orbits in the core's field. Then every particle, core included, feels every other particle. Nothing holds the disks circular after that.
$$ \mathbf{a}_i = \sum_{j \neq i} \frac{G m_j \, \mathbf{r}_{ij}}{(r_{ij}^2 + \varepsilon^2)^{3/2}} $$
The force is Newtonian gravity with Plummer softening, so the acceleration stays finite when two stars pass through the same point. A Barnes-Hut tree evaluates it, opening angle 0.7: a distant clump of stars is one mass at their center of mass, a close clump is opened. The step is velocity Verlet, the kick-drift-kick leapfrog. It is symplectic, which is the reason a long collision does not heat itself from the time step the way a plain Euler update would.
Mass ratio, impact parameter, and approach speed rebuild the initial conditions. Softening you can change while it runs. On a small screen the disk is thinner, so the same step stays inside a frame. One fixed step per frame: if the display stutters, the collision slows down. It does not take a bigger step and fall apart.
What you want to see is the tails. Stars on the far side of each disk keep the speed they had, while the near side is pulled ahead. The disk cannot stay round. That is the whole trick, and it is only the force law.
Field note: When two galaxies pass. Draft for Ali to write. It is not published yet.