Squeak Class Documentation category index | class index  
 
BouncingAtomsMorph
  category: Morphic-Demo
  superclass: Morph
  subclasses:

This morph shows how an ideal gas simulation might work. When it gets step messages, it makes all its atom submorphs move along their velocity vectors, bouncing when they hit a wall. It also exercises the Morphic damage reporting and display architecture. Here are some things to try:

1. Resize this morph as the atoms bounce around.
2. In an inspector on this morph, evaluate "self addAtoms: 10."
3. Try setting quickRedraw to false in invalidRect:. This gives the
default damage reporting and incremental redraw. Try it for
100 atoms.
4. In the drawOn: method of AtomMorph, change drawAsRect to true.
5. Create a HeaterCoolerMorph and embed it in the simulation. Extract
it and use an inspector on it to evaluate "self velocityDelta: -5", then
re-embed it. Note the effect on atoms passing over it.

instance methods
  initialization
  initialize

  menu
  addCustomMenuItems:hand:
setAtomCount
startInfection

  other
  addAtoms:
addMorphFront:
areasRemainingToFill:
collisionPairs
drawOn:
invalidRect:from:
showInfectionHistory:
transmitInfection
updateTemperature:

  stepping
  step
stepTime

class methods
  other
  descriptionForPartsBin

instance methods
  initialization top  
 

initialize


  menu top  
 

addCustomMenuItems:hand:

Add morph-specific items to the given menu which was invoked by the given hand. This method provides is invoked both from the halo-menu and from the control-menu regimes.


 

setAtomCount


 

startInfection


  other top  
 

addAtoms:

Add a bunch of new atoms.


 

addMorphFront:

Called by the 'embed' meta action. We want non-atoms to go to the back.


 

areasRemainingToFill:

May be overridden by any subclasses with opaque regions


 

collisionPairs

Return a list of pairs of colliding atoms, which are assumed to be
circles of known radius. This version uses the morph's positions--i.e.
the top-left of their bounds rectangles--rather than their centers.


 

drawOn:

Clear the damageReported flag when redrawn.


 

invalidRect:from:

Try setting 'quickRedraw' to true. This invalidates the entire morph, whose bounds typically subsume all it's submorphs. (However, this code checks that assumption and passes through any damage reports for out-of-bounds submorphs. Note that atoms with super-high velocities do occaisionally shoot through the walls!) An additional optimization is to only submit only damage report per display cycle by using the damageReported flag, which is reset to false when the morph is drawn.


 

showInfectionHistory:

Place a graph of the infection history in the world.


 

transmitInfection


 

updateTemperature:

Record the current temperature, which is taken to be the number of atoms that have bounced in the last cycle. To avoid too much jitter in the reading, the last several readings are averaged.


  stepping top  
 

step

Bounce those atoms!


 

stepTime

As fast as possible.


class methods
  other top  
 

descriptionForPartsBin

If the receiver is a member of a class that would like to be represented in a parts bin, answer the name by which it should be known, and a documentation string to be provided, for example, as balloon help. When the 'nativitySelector' is sent to the 'globalReceiver', it is expected that some kind of Morph will result. The parameters used in the implementation below are for documentation purposes only!