Print

Print


SparseGridPortryal2D doesn't use color maps.  There are three ways to do it:

1. If you want to differentiate color based on the *java class* of the 
object, you can use setPortrayalForClass

2. If you want to differentiate color based on individual instances, you 
can use setPortrayalForObject

3. A little faster is to let the instances be their own portrayals.  If 
they're subclasses of SimplePortrayal2D, the system will let them 
portray themselves.

For more detail, check out the class documentation for 
sim/portrayal/Portrayal.java

Also: if you have a high degree of objects, and they're never allowed to 
be in the same location, you may wish instead to use an ObjectGrid (just 
a 2D array of Objects) and the FastObjectGridPortrayal2D, which displays 
objects as colored rectangles (only).  In some cases this portrayal is 
faster.  The way this portrayal works is as follows: you associate a 
ColorMap (a mapping of numbers -> colors, use SimpleColorMap to make 
your life easy).  Then you have to have your objects return numbers. 
The easiest way to do this is to have them override the 
sim.util.Valuable interface.  Then FastObjectGridPortrayal2D will 
portray them as rectangles of various colors, and can do so pretty rapidly.

Sean

Randy Latimer wrote:
> I have a grid of "culture" agents, each one has a different color based on features of the culture.
> 
> I don't know how to portray a grid of agents (here - class Culture) in which each agent can have it's own color.
> 
> setPortrayalForAll() colors all of the agents the same.  I don't know how to 
> "setPortrayalForEach"
> 
> In the code segment below, getColorIndex() could access the color for each agent in a Bag.  Is this the general idea?
> Thanks
> Randy Latimer
> 
> 
>  SparseGridPortrayal2D individCulturePortrayal = new SparseGridPortrayal2D()
> ...
>  individCulturePortrayal.setField(((CultureWorld)state).getCultureGrid());
>  
>  individCulturePortrayal.setPortrayalForAll(
> 	       new sim.portrayal.simple.RectanglePortrayal2D(
> 			colorMap[((CultureWorld)state).getColorIndex()],.8) );