swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Making a zoomraster displaying MoGrid2d. Would you have done this?


From: Paul Johnson
Subject: Making a zoomraster displaying MoGrid2d. Would you have done this?
Date: Wed, 23 Jun 1999 16:41:23 -0500

Is there a color code for "transparent" in the Swarm colormap setup?  

That's my specific question, now here's a nice big softball for you to
bat around.
I just finished coding up a little app and I wondered if any of you
would have done this.

I used Sven's MoGrid2d class as the basis for the "positionGrid" of the
agents. Then I wanted to display summary information about each point in
the MoGrid2d object on the zoomraster. Unfortunately, it is not
straightforward how this can be done. I wanted the points on the raster
to reflect the state of the list at each point by using colors.  I.e., a
list that is low would show dark blue, a list that is high would show
light blue.

The problem is that the MoGrid2d uses a Swarm List at each point in the
grid.  That means it is not possible to add a method drawSelfOn, since
List can't be subclaseed. I considered for a while making a new wrapper
class around list, and then putting those wrappers inside the MoGrid2d. 
I think that would have worked, but I was afraid of destroying the
essence of MoGrid2d by building in another layer of abstraction.

So here is what I did.

I created a second Discrete2d grid, called "objectHolderGrid," same size
as the positionGrid, and a new object class wrapper called
"ValueHolder".  The ValueHolder class can set its own position in a
lattice and it can store values of variables. Most importantly, it has
drawSelfON.  Whenever MoGrid2d creates a list for itself at a particular
point, it also creates a ValueHolder object and puts it in the
objectHolderGrid at the same coordinates.  Changes that happen to the
lists in positionGrid are reflected by changes in the values in
objectHolderGrid. And it all shows up in the zoomraster with a method
likethis in ObserverSwarm.

 protestDisplay = [Object2dDisplay createBegin: self];
  [protestDisplay setDisplayWidget: worldRaster];
  [protestDisplay setDiscrete2dToDisplay: [modelSwarm
getHolderObjectGrid]];
  //Note, there is no line such as this here:
  //    [protestDisplay setObjectCollection: [modelSwarm getCitizenList]];

  [protestDisplay setDisplayMessage: M(drawSelfOn:)];   // draw method
  protestDisplay = [protestDisplay createEnd];

One minus of my approach is that I have to omit the setObjectCollection
line above, which forces the protestDisplay to go square by square over
the whole lattice when rendering.  I tried to think of a way to mungle
the objectHolderGrid into a list, but I kept losing funcitonality by
doing so.

#begin obnoxious moralizing
Incidentally, I am now persuaded anything possible in Swarm should be
geared to work with OPEN SOURCE tools, compilers, IDEs, etc. It is just
a matter of principle.  It is better to make participation open to all
who are willing to make the effort than it is to exclude some by making
participation contingent on ownership of certain commercial products. I
withdraw any comments I might have made in the past which seem to flow
in the other direction.  I now officially love Emacs.  Well, Xemacs, but
I'm trying to work my way up to Emacs.
#end obnoxious moralizing
 

-- 
Paul E. Johnson                       email: address@hidden
Dept. of Political Science            http://lark.cc.ukans.edu/~pauljohn
University of Kansas                  Office: (785) 864-9086
Lawrence, Kansas 66045                FAX: (785) 864-5700

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]