I tried this, but it messes up the locations of the objects horribly, as if I've scaled the entire grid or something:
OvalPortrayal2D myPortrayal = new OvalPortrayal2D(Color.WHITE, maxOvalSize) {
@Override
public void draw(Object object, Graphics2D graphics, DrawInfo2D drawInfo)
{
MyObject ob = (MyObject) object;
double objectScale = ob.getAttribute();
graphics.scale(objectScale, objectScale);
super.draw(object, graphics, drawInfo);
}
};
On Wed, Aug 1, 2012 at 4:48 PM, Sean Luke
<[log in to unmask]> wrote:
On Aug 2, 2012, at 5:19 AM, Luís de Sousa wrote:
> I have a SparseGrid harbouring objects of assorted classes. I'd like
> to portray one of these classes with a ColourMap, like it is made with
> ValueGrid. This way each object would be portrayed with a different
> colour gradient depending on a particular attribute. Is this possible
> to do? How?
SparseGrid does not support color maps directly. But it's easy enough to do it. Choose or create a SimplePortrayal to display your object. Let's say it's OvalPortrayal2D. Then you can say:
final SimpleColorMap map = new SimpleColorMap( ....... ); // set it up like you'd like
OvalPortrayal2D oval = new OvalPortrayal2D()
{
public void draw(Object object, Graphics2D graphics, DrawInfo2D info)
{
MyObjectClass obj = (MyObjectClass) object;
double val = obj.getMyAttribute();
paint = new Color(map.getColor(val));
super.draw(object, graphics, info);
}
};
Then just use 'oval' as your portrayal.
Sean
--
Ph.D. Student in Computer Science
Volgenau School of Engineering
George Mason University