diff --git a/PBox.pde b/PBox.pde index 3b20a27..ef81d07 100644 --- a/PBox.pde +++ b/PBox.pde @@ -69,7 +69,9 @@ public HashMap grid = new HashMap(); // Keep track of which cell a given cell is supposed to swap with. Used to find and prevent // conflicting swaps. -// Using a cell location as a key, holds the target location that this cell is proposed to swap with +// Using a cell location as a key, holds a list of target locations that this cell is proposed to swap with. +// To skip conflicts, we can make sure a pair of cells only is designated to swap with one another; +// If a swap is valid, cell A should list only cell B as a swap target, and cell B should list just cell A. public HashMap> swaps = new HashMap>(); // List of all cells @@ -80,15 +82,15 @@ public ArrayList evenCells = new ArrayList(); // List of cells in imaginary plane public ArrayList oddCells = new ArrayList(); +//For placing a predfined module (list of cells) public ArrayList moduleCells = new ArrayList(); // store state of all cells, so we can reset back to original config in RAM public ArrayList stashCells = new ArrayList(); int stashedClock = 0; -// for drawing center of mass trails +// for drawing center of mass trails, uses floating point values, hence PVector instead of Coord public PVector[] trail = new PVector[trailSize]; - // clear the grid and regenerate it from cells void resetGrid() { grid.clear(); diff --git a/RootGUI.pde b/RootGUI.pde index b2eb744..b8c5a6b 100644 --- a/RootGUI.pde +++ b/RootGUI.pde @@ -16,7 +16,7 @@ ItemListener { JLabel movieLabel = new JLabel("Write Movie: off", JLabel.LEFT); JLabel ncellsLabel = new JLabel("# cells: "+allCells.size(), JLabel.LEFT); - + JLabel help = new JLabel(HELP_STRING, JLabel.LEFT); @@ -29,12 +29,20 @@ ItemListener { + JMenuItem saveConfigItem = new JMenuItem("Save Config"); JMenuItem clearItem = new JMenuItem("Clear"); JMenuItem loadConfig = new JMenuItem("Load Config"); JMenuItem loadModule = new JMenuItem("Load Module"); JMenu file = new JMenu("File"); + JMenu gridMenu = new JMenu("Grid"); + JMenuItem grid16 = new JMenuItem("16"); + JMenuItem grid32 = new JMenuItem("32"); + JMenuItem grid64 = new JMenuItem("64"); + JMenuItem grid128 = new JMenuItem("128"); + + JButton updateButton = new JButton("STASH"); JButton resetButton = new JButton("RESTORE"); JButton clearButton = new JButton("CLEAR"); @@ -56,6 +64,17 @@ ItemListener { ruleList.addActionListener(this); ruleList.setAlignmentX(Component.LEFT_ALIGNMENT); + gridMenu.add(grid16); + grid16.addActionListener(this); + gridMenu.add(grid32); + grid32.addActionListener(this); + gridMenu.add(grid64); + grid64.addActionListener(this); + gridMenu.add(grid128); + grid128.addActionListener(this); + + + updateButton.addActionListener(this); resetButton.addActionListener(this); clearButton.addActionListener(this); @@ -80,6 +99,7 @@ ItemListener { loadModule.addActionListener(this ); menuBar.add(file); + menuBar.add(gridMenu); setJMenuBar(menuBar); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); @@ -148,6 +168,14 @@ ItemListener { app.fast = !app.fast; } else if (cmd.equals("FORWARD/BACK")) { app.toggleTime(); + } else if (cmd.equals("16")) { + app.gridSize = 16; + } else if (cmd.equals("32")) { + app.gridSize = 32; + } else if (cmd.equals("64")) { + app.gridSize = 64; + } else if (cmd.equals("128")) { + app.gridSize = 128; } } @@ -171,3 +199,4 @@ ItemListener { +"': toggle default cursor value
" +""; } + diff --git a/Rule3.pde b/Rule3.pde index 163d1b7..032c5dd 100644 --- a/Rule3.pde +++ b/Rule3.pde @@ -27,119 +27,61 @@ class Rule3 extends Rule { b = new Coord(x2, y2, z2); } } - // moves XY plane - - Swap dxy1 = new Swap( - 1, 0, 0, - 1, 0, 0); - - - Swap dxy2 = new Swap( - 1, 0, 0, - 0, 1, 0); - - Coord testxy = new Coord(4, 0, 0); - - // moves XZ plane - - Swap dxz1 = new Swap( - 0, 0, 1, - 1, 0, 2); - - Swap dxz2 = new Swap( - 0, 1, 0, - 0, 0, 1); - - Coord testxz = new Coord(0, 0, 4); - - // moves YZ plane - Swap dyz1 = new Swap( - 0, 1, 0, - 0, 2, 1); - - Swap dyz2 = new Swap( - 0, 0, 1, - 1, 0, 0); - - Coord testyz = new Coord(0, 4, 0); void runRule() { int phase = clockPhase(); - ArrayList cells; - if (phase % 2 == 0) { - cells = evenCells; - } else { - cells = oddCells; - } - switch(phase) { case 0: - rule3(cells, dxy1, dxy2); + rule3(evenCells, phase); break; case 1: - rule3(cells, dxz1, dxz2); + rule3(oddCells, phase); break; case 2: - rule3(cells, dyz1, dyz2); + rule3(evenCells, phase); break; case 3: - rule3(cells, dxy1, dxy2); + rule3(oddCells, phase); break; case 4: - rule3(cells, dxz1, dxz2); + rule3(evenCells, phase); break; case 5: - rule3(cells, dyz1, dyz2); + rule3(oddCells, phase); break; } } - Coord ptest1 = new Coord(0, 0, 0); - Coord ptest2 = new Coord(0, 0, 0); - - void rule3(ArrayList cells, Swap s1, Swap s2) { + void rule3(ArrayList cells, int phase) { for (Cell cell : cells) { - addCoords(cell.loc, s1.a, p1); // p1 := cell + delta1 - addCoords(cell.loc, s1.b, p2); // p1 := cell + delta1 - Cell cell1 = grid.get(p1); - Cell cell2 = grid.get(p2); - - if ((cell2 != null && cell.state != cell2.state ) || (cell1 != null && cell.state != cell1.state )) { - addCoords(cell.loc, s1.a, p1); // p1 := cell + delta1 - addCoords(cell.loc, s1.b, p2); // p1 := cell + delta1 + switch(phase) { + case 0: + case 1: + p1.set(cell.loc); + p2.set(cell.loc); + p1.x -= 1; + p2.x -= 3; proposeSwap(p1, p2); - subCoords(cell.loc, s1.a, p1); // p1 := cell + delta1 - subCoords(cell.loc, s1.b, p2); // p1 := cell + delta1 - proposeSwap(p1, p2); - } else { - - addCoords(cell.loc, s2.a, p1); // p1 := cell + delta1 - addCoords(cell.loc, s2.b, p2); // p1 := cell + delta1 - proposeSwap(p1, p2); - - subCoords(cell.loc, s2.a, p1); // p1 := cell + delta1 - subCoords(cell.loc, s2.b, p2); // p1 := cell + delta1 + p1.set(cell.loc); + p2.set(cell.loc); + p1.x += 1; + p2.x += 3; proposeSwap(p1, p2); + break; } } } - // the default starting configuration - void initConfig() { - int n = 14; - int x=0; - int y=0; - int z=0; - while (n-- > 0) { - addCell(x, y, z, 1); - y++; - } + + void initConfig() { + addCell(0, 0, 0, 1); + addCell(1, 0, 0, 1); } } diff --git a/Rule4.pde b/Rule4.pde index ed1de55..433fe59 100644 --- a/Rule4.pde +++ b/Rule4.pde @@ -135,7 +135,7 @@ class Rule4 extends Rule { for (int x = -N; x < N; x+=1) { for (int y = -N; y < N; y+=2) { for (int z = -N; z < N; z+=2) { - addCell(x, y, z, round(random(-1,1))); + addCell(x, y, z, round(random(-1, 1))); } } } diff --git a/Rule5.pde b/Rule5.pde index 7d04fd9..f8937fd 100644 --- a/Rule5.pde +++ b/Rule5.pde @@ -94,3 +94,4 @@ class Rule5 extends Rule { } } } +