MASON-INTEREST-L Archives

June 2016

MASON-INTEREST-L@LISTSERV.GMU.EDU

Options: Use Monospaced Font
Show Text Part by Default
Condense Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Sender:
MASON Multiagent Simulation Toolkit <[log in to unmask]>
Date:
Fri, 24 Jun 2016 13:14:59 -0400
MIME-version:
1.0 (Mac OS X Mail 7.3 \(1878.6\))
Reply-To:
MASON Multiagent Simulation Toolkit <[log in to unmask]>
Content-type:
text/plain; charset=iso-8859-1
Subject:
From:
Sean Luke <[log in to unmask]>
In-Reply-To:
Message-ID:
Content-Transfer-Encoding:
8bit
Parts/Attachments:
text/plain (99 lines)
The default trail for MASON has a width of 0.5f.  However you could make a new trail.  Here is one that is 0.1f:

public class MyTrail extends SimpleEdgePortrayal2D
        {
        BasicStroke stroke = new BasicStroke(0.1f,    /// NOTE HERE!!!!!
		BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
        public void draw(Object object, Graphics2D graphics, DrawInfo2D info)
            {
            info.precise = true;  // force non-awt graphics
            float linewidth = stroke.getLineWidth();
            if (linewidth * 2 != info.draw.width)
                stroke = new BasicStroke((float)(info.draw.width / 2),
			BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
            graphics.setStroke(stroke);
            TrailedPortrayal.TrailDrawInfo2D t = (TrailedPortrayal.TrailDrawInfo2D) info;
            toPaint = fromPaint = defaultMap.getColor(t.value);
            super.draw(object, graphics, info);
            }
        }

You could use it like this:

new TrailedPortrayal(....., new MyTrail(), ...);

Sean




On Jun 6, 2016, at 2:26 PM, Giovanni Reina <[log in to unmask]> wrote:

> Hi,
> 
> I recently upgraded my Mason from version 1.6 to v.1.9.
> 
> My previous code seems to work fine except for one thing.
> Now when I visualise the agent's trail, it is very thick!
> My agents are only 0.5 big and the trail has the same 0.5 size.
> 
> I tried to change the trail width without success.
> Someone knows how is it possible to change that?
> 
> 
> I paste here the relevant code of my GUI class:
> 
> public class SpatialCaseStudyWithUI extends GUIState {
> 
> ......
> ContinuousPortrayal2D trailsPortrayal = new ContinuousPortrayal2D();
> 
> public SimplePortrayal2D makeAgent(){
> return new TrailedPortrayal2D(
>                 this,
>                 new OrientedPortrayal2D( new SimplePortrayal2D(), 0, 0.5, new Color(255, 0, 0),
>                 OrientedPortrayal2D.SHAPE_COMPASS){
> public void draw(Object object, Graphics2D graphics, DrawInfo2D info){
> MyState myState =((SpatialAgent)object).commitmentState; 
> paint = (myState == MyState.UNCOMMITTED)? new Color(255, 255, 255) : (myState == MyState.OPTION_1)? new Color(150, 0, 0) : new Color(0, 100, 0) ;
> super.draw(object, graphics, info);
> }
>                 }, trailsPortrayal, 100);
> 
> }
> 
> 
> public void setupPortrayals() {
>   .....
>    trailsPortrayal.setField( currentState.arena );
>   arenaPortrayal.setField( currentState.arena );
>   for(int x=0; x < currentState.arena.allObjects.numObjs; x++) {
> SimplePortrayal2D p = makeAgent();
> arenaPortrayal.setPortrayalForObject(currentState.arena.allObjects.objs[x], new MovablePortrayal2D(p));
> trailsPortrayal.setPortrayalForObject(currentState.arena.allObjects.objs[x], p);
>   }
>  .....
> }
> 
> 
> 
> 
> 
> I tried to modify the draw method by adding (before the super.draw) this code:
> 
> BasicStroke stroke = new BasicStroke(0.1f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
> graphics.setStroke(stroke);
> 
> but it didn't help.
> 
> Any advice is welcome.
> Thanks,
> Giovanni
> 
> 
> -- 
> Andreagiovanni Reina
> Research Associate in Collective Robotics
> University of Sheffield, UK
> http://areina.staff.shef.ac.uk

ATOM RSS1 RSS2