from PythonLabs.SphereLab import Body
from PythonLabs.Canvas import Canvas

def step_system(bodies, dt):   
    """
    Carry out one time step of an n-body simulation.  The two arguments
    passed to the function are a list of Body objects and the time step size.
    """
    nb = len(bodies)          # nb = "number of bodies"

    for i in range(0, nb):    # compute pairwise interactions
        for j in range(i+1, nb):
            Body.interaction( bodies[i], bodies[j] )

    for b in bodies:
        b.move(dt)            # apply the accumulated forces
        b.clear_force()       # reset force for next round

    if Canvas.view:
        Canvas.update()
