Quantcast

Dynamically changing agent representation on display

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Dynamically changing agent representation on display

foxtrotalpha
Hi everyone,

Apologies for the super basic question but I can't seem to figure this out.

First some context: I've built a game of life model as a Repast learning
exercise and have managed to get it running pretty well. However the model
is quite kludgy in my opinion, as I have had to make two agent classes (one
for live and one for dead cells) with largely repetitive code.

To display, I have set the display settings to show the dead agent instances
as white and the live ones as blue, which is not exactly an elegant
solution.

I want to simplify my code by using only one agent class and giving it a
state variable to determine whether it is alive or dead.

How can I make it so that the agents display differently (in terms of color
in this case) based on that state variable?

Thanks,
FA



--
View this message in context: http://repast.10935.n7.nabble.com/Dynamically-changing-agent-representation-on-display-tp11498.html
Sent from the repast-interest mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Dynamically changing agent representation on display

srcnick
You can use a style class to set the color etc. of an agent based on a field. The simplest way to do this is to extend DefaultStyle2D:

public class LifeAgentStyle extends DefaultStyleOGL2D {

        public Color getColor(Object o) {
                LifeAgent agent = (LifeAgent)o;
                if (agent.isAlive()) return Color.RED;
                return Color.BLUE;
        }
}

In the Display Wizard enter the fully qualifed name of this class as the Style Class.

Nick


> On Apr 29, 2016, at 8:27 AM, foxtrotalpha <[hidden email]> wrote:
>
> Hi everyone,
>
> Apologies for the super basic question but I can't seem to figure this out.
>
> First some context: I've built a game of life model as a Repast learning
> exercise and have managed to get it running pretty well. However the model
> is quite kludgy in my opinion, as I have had to make two agent classes (one
> for live and one for dead cells) with largely repetitive code.
>
> To display, I have set the display settings to show the dead agent instances
> as white and the live ones as blue, which is not exactly an elegant
> solution.
>
> I want to simplify my code by using only one agent class and giving it a
> state variable to determine whether it is alive or dead.
>
> How can I make it so that the agents display differently (in terms of color
> in this case) based on that state variable?
>
> Thanks,
> FA
>
>
>
> --
> View this message in context: http://repast.10935.n7.nabble.com/Dynamically-changing-agent-representation-on-display-tp11498.html
> Sent from the repast-interest mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Find and fix application performance issues faster with Applications Manager
> Applications Manager provides deep performance insights into multiple tiers of
> your business applications. It resolves application problems quickly and
> reduces your MTTR. Get your free trial!
> https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
> _______________________________________________
> Repast-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/repast-interest


------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Loading...