⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lsystemwithui.java

📁 MASON代表多主体邻里或网络仿真(Multi-Agent Simulator of Neighborhoods or Networks)。它是乔治梅森大学用Java开发的离散事件多主体仿真核心库
💻 JAVA
字号:
package sim.app.lsystem;import sim.engine.*;import sim.display.*;import sim.portrayal.continuous.*;import java.awt.*;import javax.swing.*;public class LsystemWithUI extends GUIState    {    public Display2D display;    public JFrame displayFrame;    public static Console c;    private ContinuousPortrayal2D systemPortrayal = new ContinuousPortrayal2D();    public static void main(String[] args)        {        LsystemWithUI lsystem = new LsystemWithUI();        c = new Console(lsystem);        c.setVisible(true);        }        public LsystemWithUI() { super(new Lsystem(System.currentTimeMillis())); }        public LsystemWithUI(SimState state) { super(state); }        public String getName() { return "Lsystem"; }        // returns the HTML info for the Console    public String getInfo()        {        Lsystem ls = (Lsystem) state;                return             "<H2>Lindenmayer Systems</H2>" +            "by Dan Kuebrich<br><br>" +            "<br>" +            "A little about L-systems:<br>" +            "<a href=\"http://www.biologie.uni-hamburg.de/b-online/e28_3/lsys.html\">http://www.biologie.uni-hamburg.de/b-online/e28_3/lsys.html</a><br>" +            "<br>" +            "<b>To use:</b><br>" +            "- Enter desired seed and rules in the appropriate boxes<br>" +            "- Enter number of expansions and click \"Calculate\" to ready the system<br>" +            "- Once this is done, choose the drawing preferences and press set<br>" +            "- Now press the play button on this console to draw the system<br>" +            "<p>There is a nice ruleset available in the Lsystem directory, called \"radicans.lss\".  Try loading it, then clicking \"Calculate\", then pressing play.  It takes a while to finish -- you might want to hide the display window to speed things up." +            "<br>";         }        public void start()        {        super.start();        setupPortrayals();        }        public void load(SimState state)        {        super.load(state);        setupPortrayals();        }            public void setupPortrayals()        {        // this portrayal will draw the objects in the drawEnvironment field...         // which contains all the segments that make up the tree.        systemPortrayal.setField(((Lsystem)state).drawEnvironment);                        // reschedule the displayer        display.reset();                        // redraw the display        display.repaint();        }        public void init(Controller c)        {        super.init(c);                // make the display2d in all of its glory        display = new Display2D(400,400,this,1); // at 400x400, we've got 4x4 per array position                // No clipping!        // The effect of this call becomes apparent when the display is zoomed out (zoom factor < 1)        // -- instead of drawing the boundaries of your field and clipping there, the display        // instead draws the entire view window, allowing you to view areas that are out of bounds.        // This is useful when your L-system starts to go off the edge of the display.        display.setClipping(false);                displayFrame = display.createFrame();        c.registerFrame(displayFrame);   // register the frame so it appears in the "Display" list        displayFrame.setVisible(true);        // attach the portrayals        display.attach(systemPortrayal,"Lsystem");        // specify the backdrop color  -- what gets painted behind the displays        display.setBackdrop(Color.white);                // setup the defaults        Lsystem ls = (Lsystem)state;        Lsys.setVector(ls.l.code, "F");        ls.l.seed = "F";                ls.l.rules.add(new Rule((byte)'F', "F[+F]F[-F]F"));                        // You have been granted the power to both create and destroy at whim...        // create and destroy the tabs on the Console anyway.        // Here we remove the Inspectors tab.        // Be careful though!  In order to safely remove this, you must make sure that your portrayals have         // the hitObjects function overridden so that it never returns an object to be inspected..        ((Console)c).getTabPane().removeTabAt(3);        // add drawUI as tab        DrawUI draw = new DrawUI(this);        ((Console)c).getTabPane().addTab("Draw", new JScrollPane(draw));        // add rulesUI as tab        ((Console)c).getTabPane().addTab("Rules", new RuleUI(this, draw));        }            public void quit()        {        super.quit();                if (displayFrame!=null) displayFrame.dispose();        displayFrame = null;  // let gc        display = null;       // let gc        }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -