Print

Print


Hello all. I am using MASON v19 in the Eclipse environment. I'm currently building an opinion dynamics model and am trying to get the visualization working where I can show agents moving along the x-axis, with each increment being a time step, and how their opinion shifts, with the y-axis being some real value on the range [0, 1].

I am using a Continuous2D field for the agents, of size 100, 100. I scale the agent opinions against the field height dimension and it appears to be right (i.e., for an opinion of 0.5, the agent shows up on the visualization in the middle of the y-axis). Each agent stores a data collection (ArrayList) of its opinions as they change over time, and this was with the intention of drawing a line to track an individual's opinion as it evolves.

Using the examples from the documentation, I attach the following overlay portrayal to the display.

    FieldPortrayal2D overlay = new FieldPortrayal2D()
    {
	    public void draw(Object object, Graphics2D graphics, DrawInfo2D info)
	    {
	        graphics.setColor(Color.blue);
	        
                // loop through all the agents in the population.
	    	for (Agent a : OpDyn_Controller.population)
	    	{
	    		int n = a.opinionHistory_x.size();

                        // loop through the opinion history of the agent, redrawing the history on every repaint.
	    		for (int i = 1; i < n; i++)
	    		{ 
	    			int x1 = a.opinionHistory_x.get(i - 1);
	    			int y1 = a.opinionHistory_yScaled.get(i - 1);
	    			int x2 = a.opinionHistory_x.get(i);
	    			int y2 = a.opinionHistory_yScaled.get(i);
	    			
	    			graphics.drawLine(x1, y1, x2, y2);
	    		}
	    	}
	    }
    };

Using console outputs, it seems that the (x1, y1), (x2, y2) coordinates for drawing a line between them match with the values of the agent's object location, however the lines that end up drawing are way offset and draw up near the top left of the screen (by the origin point). Relative spacing between the lines and between the agents seem to be consistent, thus, it appears to be a scaling issue? Does the graphics.drawLine method use a different coordinate scaling system than placing agents into the world and updating their locations?

Thank you for any advice!
Brant