简体   繁体   中英

Cellular automata on a Hex grid

I'm learning java so I try to code a basic cellular automata on a hexgrid.

I want to separate display code from simulation code so the simulation just process calculations and the display refresh itself based on it.

I try to figure out for days how to properly do this but I'm still confused. I've found many resources on the internet but none gives a simple walkthrough to code this in a object oriented way.

For now I don't care about implementing any pattern, a simple continuous movement on the x and y axes would be good enough to check if it works.

So what I've done :

  • a GUI with go, pause, clear controls and a blank display Jpanel

If somebody could give me a method or skeleton or any advice on how to achieve this it'd be really appreciated.

pseudocode:

class MyModel {
    private int x;
    private int y;

    public int getX() { return x; }
    public int getY() { return y; }

    public void go() {
        // sart a thread that changes x & y over time
    }
    public void stop() {
        // stop the thread
    }
    public void reset() {
        // reset x & y to their initial values
    }
}

The above is your model. Your view should monitor changes in the model's x and y values and display movement based on that. Your controller should call the model's "go" method when the user taps the "go" button, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM