In the planar version, an acceleration vector is created each generation for each particle based on the masses and relative positions of all other particles. Then the acceleration vector is added to the velocity vector which is added to the position vector. This is done repeatedly to simulate the movement of the particles due to gravity.
In the toroidal version, this is repeated with integer shifts 25 times in the x direction and 25 in the y direction, for a grand total of 625 times, approximating the sum over infinitely many shifts over the whole plane.
Obviously, this takes more time for more particles, and 625 times more time for the toroidal version than the planar version. Keep this in mind when pushing big buttons.
Geoscience -- Topographical Maps:restart:with(plots): a := -2: b := 2: # x domain c := -2: d := 2: # y domain p := 0.22: q := 1.83: # range n := 6: # frames f := (x,y) -> 2*(sin(x*y*7)/8+cos((x+y/2)*5)/6+ sin((x-y)*3)/4+1-cos(x*y)/3)/(1+x^2+y^2)^.8: an1 := plot3d(f(x,y),x=a..b,y=c..d,grid=[20,20],view=p..q+.1): for k from 0 to n do an2[ 2*k ] := plot3d(q-k/n*(q-p),x=a..b,y=c..d,grid=[2,2], color=white): an2[2*k+1] := an2[2*k]: an3[ k ] := implicitplot3d(f(x-b+a,y)=q-(q-p)*k/n, x=b..2*b-a,y=c..d,z=p..p+.001,numpoints=400): end do: an4[0] := an3[0]: an4[1] := an4[0]: for k from 1 to n do an4[ 2*k ] := display(an4[2*k-2],an3[k]): an4[2*k+1] := an4[2*k]:
end do: an5 := plots[display]([seq(an2[i],i=0..2*n+1)],insequence=true): an6 := plots[display]([seq(an4[i],i=0..2*n+1)],insequence=true): display(an1,an5,an6,scaling=constrained);