next up previous
Next: Dynamics Up: From bouncing balls to Previous: Minimisation

Displaying it visually

So we have built our structure, and we've done something with it, now we want to display it on the screen. This is quite similar to the bouncing balls example. We create an array of balls, the same length as the array of atoms. We then use the vectors in the array of atoms to position them. Each time the position of an atom changes, we go through and mirror the change in the array of balls.

First we create the balls with the initial position:

<Create Balls>=
balls = []
for atom in atoms:
    balls.append(sphere(pos=atom, color=color.blue, radius=0.3))
Used above (1), below (2).

then each time we want to update the position:

<Move Balls>=
for i in range(len(atoms)):
    balls[i].pos = atoms[i]
Used above (1), below (2).



James Roper 2004-02-12