sim.app.flockers.FlockersWithUI Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mason Show documentation
Show all versions of mason Show documentation
MASON is a fast discrete-event multiagent simulation library core in Java, designed to be the foundation for large custom-purpose Java simulations, and also to provide more than enough functionality for many lightweight simulation needs. MASON contains both a model library and an optional suite of visualization tools in 2D and 3D.
The newest version!
/*
Copyright 2006 by Sean Luke and George Mason University
Licensed under the Academic Free License version 3.0
See the file "LICENSE" for more information
*/
package sim.app.flockers;
import sim.engine.*;
import sim.display.*;
import sim.portrayal.continuous.*;
import javax.swing.*;
import java.awt.*;
import sim.portrayal.simple.*;
import sim.portrayal.SimplePortrayal2D;
public class FlockersWithUI extends GUIState
{
public Display2D display;
public JFrame displayFrame;
public static void main(String[] args)
{
new FlockersWithUI().createController(); // randomizes by currentTimeMillis
}
public Object getSimulationInspectedObject() { return state; } // non-volatile
ContinuousPortrayal2D flockersPortrayal = new ContinuousPortrayal2D();
// uncomment this to try out trails (also need to uncomment out some others in this file, look around)
ContinuousPortrayal2D trailsPortrayal = new ContinuousPortrayal2D();
public FlockersWithUI()
{
super(new Flockers(System.currentTimeMillis()));
}
public FlockersWithUI(SimState state)
{
super(state);
}
public static String getName() { return "Flockers"; }
public void start()
{
super.start();
setupPortrayals();
}
public void load(SimState state)
{
super.load(state);
setupPortrayals();
}
public void setupPortrayals()
{
Flockers flock = (Flockers)state;
flockersPortrayal.setField(flock.flockers);
// uncomment this to try out trails (also need to uncomment out some others in this file, look around)
trailsPortrayal.setField(flock.flockers);
// make the flockers random colors and four times their normal size (prettier)
for(int x=0;x h)
{ display.insideDisplay.width = 750; display.insideDisplay.height = 750 * (h/w); }
else if (w < h)
{ display.insideDisplay.height = 750; display.insideDisplay.width = 750 * (w/h); }
// reschedule the displayer
display.reset();
// redraw the display
display.repaint();
}
public void init(Controller c)
{
super.init(c);
// make the displayer
display = new Display2D(750,750,this);
display.setBackdrop(Color.black);
displayFrame = display.createFrame();
displayFrame.setTitle("Flockers");
c.registerFrame(displayFrame); // register the frame so it appears in the "Display" list
displayFrame.setVisible(true);
// uncomment this to try out trails (also need to uncomment out some others in this file, look around)
display.attach( trailsPortrayal, "Trails" );
display.attach( flockersPortrayal, "Behold the Flock!" );
}
public void quit()
{
super.quit();
if (displayFrame!=null) displayFrame.dispose();
displayFrame = null;
display = null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy