swarm-support
[Top][All Lists]
Advanced

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

Re: [Swarm-Support] question about coloring of the background, and leavi


From: Paul E Johnson
Subject: Re: [Swarm-Support] question about coloring of the background, and leaving paths
Date: Mon, 19 May 2003 12:47:19 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20020918

Rex Oleson wrote:
Actually I have 2 seperate questions, but they might be related to each other.

1)
  I was wondering how you go about leaving a trail behind and agent. To 
demonstrate where he has been? I know I could do this by leaving an object and 
setting the color of that object appropriately, but that seem like a lot of 
work. I know also that in the termite program and a few others they appear to 
use another.

2) Is there a way to set the background color of the simulation screen, instead of the standard black?


Here's a method from an observer swarm that rewrites each of NOFSPACES rasters with color 1 from the colormap you define. Schedule that before you write on the raster and it will do what you want.

- eraseRaster
{
  // A method that overrides the default
  // black background for raster and paints
  // the raster white instead
  int i;
  for (i=0; i < NOFSPACES; i++)
    {
      [[rasters atOffset: i] fillRectangleX0: 0
                             Y0: 0
                             X1: [[modelSwarm getMDSpace] getMaxDim: 0]
                             Y1:  [[modelSwarm getMDSpace] getMaxDim: 1]
                             Color: 1];
    }
  return self;
}


If you erase the raster every time, then you will have to redraw the paths of your creatures every time. In the past, I have found this works. Create an object that can draw itself on the screen, and every time an agent goes somewhere, it creates one of these objects and puts it in a list. Then redraw the list at each timestep.

Here's a method from a model swarm that draws objects in a voterList (which is the same everytime) as well as the "winnerList", a collection of objects that gets bigger each time a winner is chosen. If you do it this way, you can customize the "draw objects" by having them put pixmaps on the screen saying "agent 1 started here" and so forth.

// This sweeps through the object that we want to draw
// themselves on the rasters, and it tells them to draw themselves.
- drawAgents
{
  id index;
  id anObject;
  index = [voterList begin: self];
for ( anObject = [index next]; [index getLoc]==Member; anObject=[index next])
    {
      [anObject drawSelfOn: observerSwarm];//??last argument unnecessary
    }
  [index drop];

  index = [winnerList begin: self];
for ( anObject = [index next]; [index getLoc]==Member; anObject=[index next])
    {
      [anObject drawSelfOn: observerSwarm];
    }
  [index drop];

  return self;
}


--
Paul E. Johnson                       email: address@hidden
Dept. of Political Science            http://lark.cc.ku.edu/~pauljohn
1541 Lilac Lane, Rm 504
University of Kansas                  Office: (785) 864-9086
Lawrence, Kansas 66044-3177           FAX: (785) 864-5700



reply via email to

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