Squeak Class Documentation category index | class index  
 
StarSqueakMorph
  category: StarSqueak-Kernel
  superclass: Morph
  subclasses: StarSqueakAntColony StarSqueakDiffusion StarSqueakForestFire StarSqueakSlimeMold StarSqueakTermites StarSqueakTrees

I implement a StarSqueak simulation. StarSqueak is a Squeak version of Mitchel Resnick's Star Logo, a simulation environment designed to explore massively parallel simulations with hundreds or thousands of turtles. See the excellent book "Turtles, Termites, and Traffic Jams: Explorations in Massively Parallel Microworlds" by Mitchel Resnick, MIT Press, 1994.

instance methods
  accessing
  diffusionRate
diffusionRate:
evaporationRate
evaporationRate:
pixelsPerPatch
pixelsPerPatch:

  drawing
  areasRemainingToFill:
display
drawOn:

  geometry
  extent:

  initialization
  initialize
initializeToStandAlone

  menu
  addCustomMenuItems:hand:
fullSpeed
makeParameterSlider
setScale
singleStep
sliderParameters
slowSpeed
startOver
startRunning
stopRunning

  patches
  clearPatches
createPatchVariable:
decayPatchVariable:
diffusePatchVariable:
patchesDo:

  private
  createPatchFormGetterAndSetter
deleteTurtle:
dimensions
displayPatchVariableOn:color:shift:
firstTurtleAtX:y:
getPatchBrightnessAtX:y:
getPatchColorAtX:y:
getPatchVariable:atX:y:
incrementPatchVariable:atX:y:by:
newSliderForParameter:target:min:max:description:
patchVariable:ifAbsent:
replicateTurtle:
setPatchBrightnessAtX:y:to:
setPatchColorAtX:y:to:
setPatchVariable:atX:y:to:
sumPatchVariable:neighborsAtX:y:
uphillOf:forTurtle:

  private-primitives
  primDiffuseFrom:to:width:height:delta:
primEvaporate:rate:
primMapFrom:to:width:height:patchSize:rgbFlags:shift:
testDiffusePrim
testEvaporatePrim

  setup
  addTurtleDemon:
addWorldDemon:
clearAll
displayPatchVariable:
displayPatchVariable:logScale:
random:
setup
starSqueakDimensions

  stepping and presenter
  oneStep
step
stepTime

  turtles
  makeTurtles:
makeTurtles:class:
turtles
turtlesAtX:y:do:
turtlesDo:

class methods
  class initialization
  initialize

instance methods
  accessing top  
 

diffusionRate


 

diffusionRate:

Set the diffusion rate to an integer between 0 and 10. The diffusion rate gives the number of patches on one size of the area averaged to compute the next value of the variable for a given patch. Larger numbers cause faster diffusion. Zero means no diffusion.


 

evaporationRate


 

evaporationRate:

Set the evaporation rate. The useful range is 0 to 25 or so. Larger numbers cause faster evaporation. Zero means no evaporization.


 

pixelsPerPatch


 

pixelsPerPatch:

Set the width of one patch in pixels. Larger numbers scale up this StarSqueak world, but numbers larger than 2 or 3 result in a blocky look. The useful range is 1 to 10.


  drawing top  
 

areasRemainingToFill:

Drawing optimization. Since I completely fill my bounds with opaque pixels, this method tells Morphic that it isn't necessary to draw any morphs covered by me.


 

display

Display this world on the Display. Used for debugging.


 

drawOn:

Display this StarSqueak world.


  geometry top  
 

extent:

Do nothing; my extent is determined by my StarSqueak world dimensions and pixelsPerPatch.


  initialization top  
 

initialize


 

initializeToStandAlone

Set up the receiver, created by a #basicNew and now ready to be initialized, as a fully-formed morph suitable for providing a graphic for a parts bin surrogate, and, when such a parts-bin surrogate is clicked on, for attaching to the hand as a viable stand-alone morph. Because of historical precedent, #initialize has been expected to handle this burden, though a great number of morphs actually cannot stand alone. In any case, by default we call the historical #initialize, though unhappily, so that all existing morphs will work no worse than before when using this protocol.


  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.


 

fullSpeed

Run at maximum speed.


 

makeParameterSlider


 

setScale


 

singleStep

Take one step and redisplay.


 

sliderParameters

Answer a list of parameters that the user can change via a slider. Each parameter is described by an array of: <name> <min value> <max value> <balloon help string>.


 

slowSpeed

Run at slow speed.


 

startOver

Restart this StarSqueak simulation from its initial conditions.


 

startRunning

Start running this StarSqueak simulation.


 

stopRunning

STop running this StarSqueak simulation.


  patches top  
 

clearPatches

Clear patch colors, including turtle trails.


 

createPatchVariable:

Create a patch variable of the given name. It is initialized to a value of zero for every patch.


 

decayPatchVariable:

Decay the values of the patch variable of the given name. That is, the value of each patch is replaced by a fraction of its former value, resulting in an expontial decay each patch's value over time. This can be used to model evaporation of a pheromone.


 

diffusePatchVariable:

Diffuse the patch variable of the given name.


 

patchesDo:

Evaluate the given block for every patch in this world.


  private top  
 

createPatchFormGetterAndSetter

Create BitBlt's for getting and setting patch colors.


 

deleteTurtle:

Delete the given turtle from this world.


 

dimensions


 

displayPatchVariableOn:color:shift:

Display patchVariableToDisplay in the given color. The opacity (alpha) of of each patch is determined by the patch variable value for that patch and shiftAmount. If shiftAmount is zero, the source value is unscaled. Positive shiftAmount values result in right shifting the source value by the given number of bits (That is, multiplying by 2^N. Negative values perform right shifts, dividing by 2^N).


 

firstTurtleAtX:y:

create turtlesAtPatchCache if necessary


 

getPatchBrightnessAtX:y:

Answer the brightness of the patch at the given location, a number from 0 to 100.


 

getPatchColorAtX:y:

Answer the color of the patch at the given location.


 

getPatchVariable:atX:y:

Answer the value of the given patch variable at the given turtle. Answer zero if the turtle is out of bounds.


 

incrementPatchVariable:atX:y:by:

Increment the value of the given patch variable at the given location by the given amount. Do nothing if the location is out of bounds.


 

newSliderForParameter:target:min:max:description:


 

patchVariable:ifAbsent:

Answer the patch variable array of the given name. If no such patch variables exists, answer the result of evaluating the given block.


 

replicateTurtle:

Create an exact copy of the given turtle and add it to this world.


 

setPatchBrightnessAtX:y:to:

Set the brightness of the patch at the given location to the given level, where 0 is black and 100 is full brightness.


 

setPatchColorAtX:y:to:

Paint the patch at the given location with the given color.


 

setPatchVariable:atX:y:to:

Set the value of the given patch variable below the given turtle to the given value. Do nothing if the turtle is out of bounds.


 

sumPatchVariable:neighborsAtX:y:

Answer the sum of the given patch variable for the eight neighbors of the patch at the given location. Answer zero if the location is out of bounds.


 

uphillOf:forTurtle:

Answer the heading the points in the direction of increasing value for the given patch variable. If there is no gradient, or if the turtle is outside the world bounds, answer the turtles current heading.


  private-primitives top  
 

primDiffuseFrom:to:width:height:delta:

Diffuse the integer values of the source patch variable Bitmap into the output Bitmap. Each cell of the output is the average of the NxN area around it in the source, where N = (2 * delta) + 1.


 

primEvaporate:rate:

Evaporate the integer values of the source Bitmap at the given rate, an integer between 0 and 1024, where 1024 is a scale factor of 1.0 (i.e., no evaporation). That is, replace each integer element v with (rate * v) / 1024.


 

primMapFrom:to:width:height:patchSize:rgbFlags:shift:

Map values in the source bitmap (interpreted as unsigned 32-bit integers) to 2x2 patches of color in the destination bitmap. The color brightness level is determined by the source value and the color hue is determined by the bottom three bits of the rgbFlags value. For example, if rgbFlags is 1, you get shades of blue, if it is 6 you get shades of yellow, and if it is 7, you get shades of gray. The shiftAmount is used to scale the source data values by a power of two. If shiftAmount is zero, the data is unscaled. Positive shiftAmount values result in right shifting the source data by the given number of bits (multiplying by 2^N, negative values perform right shifts (dividing by 2^N). The width parameter gives the width of the Form that owns the destination bitmap.


 

testDiffusePrim

This test should diffuse the initial value in the center cell so that each cell has 1000.


 

testEvaporatePrim

This test should result in reducing each element of the array to 75% of its initial value.


  setup top  
 

addTurtleDemon:

Add the given selector to the list of selectors sent to every turtle on every step.


 

addWorldDemon:

Add the given selector to the list of selectors sent to the world on every step.


 

clearAll

Reset this StarSqueak world. All patch variables are cleared, all turtles are removed, and all demons are turned off.


 

displayPatchVariable:

Make this StarSqueak world display the patch variable of the given name. Only one patch variable can be displayed at any given time.


 

displayPatchVariable:logScale:

Make this StarSqueak world display the patch variable of the given name. Only one patch variable can be displayed at any given time. Values are scaled by 2^logBase2OfScaleFactor. For example, a value of 5 scales by 32 and a value of -2 scales by 1/4.


 

random:

Answer a random integer between 0 and range.


 

setup

Subclasses should override this to setup the initial conditions of this StarSqueak world. The method should start with 'self clearAll'.


 

starSqueakDimensions

Answer the dimensions of this StarSqueak simulation. Subclasses can override this method to define their own world size.


  stepping and presenter top  
 

oneStep

Perform one step of the StarSqueak world. Execute all turtle and world demons.


 

step

Do some periodic activity. Use startStepping/stopStepping to start and stop getting sent this message. The time between steps is specified by this morph's answer to the stepTime message. The generic version dispatches control to the player, if any. The nasty circumlocation about owner's transformation is necessitated by the flexing problem that the player remains in the properties dictionary both of the flex and the real morph. In the current architecture, only the top renderer's pointer to the player should actually be honored for the purpose of firing.


 

stepTime

Answer the desired time between steps in milliseconds. This default implementation requests that the 'step' method be called once every second.


  turtles top  
 

makeTurtles:

Create the given number of generic turtles.


 

makeTurtles:class:

Create the given number of turtles of the given turtle class.


 

turtles


 

turtlesAtX:y:do:

Evaluate the given block for each turtle at the given location.


 

turtlesDo:

Evaluate the given block for every turtle. For example:
w turtlesDo: [:t | t forward: 1]
will tell every turtle to go forward by one turtle step.


class methods
  class initialization top  
 

initialize

StarSqueakMorph initialize