School "snack" help sought

Bob Arning arning at charm.net
Sun Nov 26 23:34:36 UTC 2000


On Mon, 27 Nov 2000 11:34:46 +1300 (NZDT) "Richard A. O'Keefe" <ok at atlas.otago.ac.nz> wrote:
>The obvious thing to do is to take the BouncingAtoms morph and hack that,
>but I really have _not_ got my head around Morphic yet.
>
>Or any suggestions about how to do this?

Richard,

The first level of hacking here is easy. BouncingAtomsMorph has a #step method which runs this simulation. It in turn sends #bounceIn: aRectangle to each of the Atoms. The AtomMorph does several things in this method:

- it determines if it has crossed the edge of the rectangle and updates its position and velocity to reflect bouncing off that wall.
- it updates its position in any case to reflect its current movement
- it returns true or false to indicate if it did bounce off a wall which enables the container to determine its temperature.

You could begin hacking at this by opening a BouncingAtomsMorph. Then get a browser and look at the AtomMorph>>bounceIn: method. As you make changes to this method, you can watch the BouncingAtomsMorph to see how that affected things. Some simple things you could try:

- assume one or more walls absorb energy from the collision (or add energy as in pinball) by changing one of the lines like:

		vx _ velocity x negated.
to
		vx _ velocity x negated * someFactor.

- or you could give each atom some goal and a limited energy supply with which to accomplish that goal. In this case you could add logic to allow an atom to decide when and how to use that energy toward its goal.

- probably more of interest is allowing atoms to interact with each other. BouncingAtomsMorph has a method #collisionPairs which reports pairs of atoms that are colliding. This could be modified to report any that are "close" and be used to inform the atoms involved so that they may try to approach or avoid the other as they desire.

And the fun thing is watching it happen before your eyes.

Cheers,
Bob





More information about the Squeak-dev mailing list