University of Virginia | CS Department at UVA | Swarm programming | Cell Simulator Tutorial

Section 2: 9. Combining Programs

Two sample programs are given below:

state center
{
  color red
  emits (alive, 1)
  diffuses (radius, 6)
  transitions
  alive from dir in { X+, X-, Y+, Y- } < 1 -> (center, fill) in dir;
}

state fill
{
  color yellow
  emits (alive, 1)
  transitions
  (alive from dir in { X+, X-, Y+, Y- } < 1) & (radius > 0) -> (fill, fill) in dir;
}
state source
{
  color green
  emits (alive, 1)
  diffuses (length, 12)
  transitions
  alive from Z+ < 1 -> (source, line) in Z+;
}

state line
{
  color magenta
  emits (alive, 1)
  transitions
  alive from Z+ < 1 & length > 0 -> (line, line) in Z+;
}
Circle.cpa Line.cpa


Now write the SIM file for combining these programs. The overall format of the SIM file is the same as for running single programs except where you list the starting state for the cell. Since the cell will run more than one program, it will start in more than one state. Where you had <state> you will now have ( <statelist> ) where statelist is just the list of starting states seperated by a space.

0: new ( center source ) 0 0 0
Circle_Line.sim

To start the simultor and combine these programs:
java gui.GUI Circle_Line.sim Circle.cpa Line.cpa

Sample outputs from a previous run are shown below:







Swarm Logo University of Virginia
Department of Computer Science
Programming the Swarm
Sponsored by the National Science Foundation
David Evans
evans@cs.virginia.edu
Selvin George
selvin@cs.virginia.edu