Browse Source

I heard you like gliders.

Grid doesn't work if dimensions are rectangular.
master
Lee 12 years ago
parent
commit
07b8b96e61
2 changed files with 18 additions and 16 deletions
  1. +13
    -9
      src/Goldfish.java
  2. +5
    -7
      src/Render.java

+ 13
- 9
src/Goldfish.java View File

@@ -7,18 +7,22 @@ public class Goldfish {
private Render _render; private Render _render;
public Goldfish() { public Goldfish() {
int height = 128;
int width = 128;
int width = 128;
int height = 128;
_grid = new Grid(width, height); _grid = new Grid(width, height);
_render = new Render(width, height, _grid); _render = new Render(width, height, _grid);
} }
public void run() { public void run() {
_grid.getPatch(1,0).setState(1);
_grid.getPatch(2,1).setState(1);
_grid.getPatch(2,2).setState(1);
_grid.getPatch(1,2).setState(1);
_grid.getPatch(0,2).setState(1);
for (int i = 0; i < _grid.getWidth(); i += 16) {
for (int j = 0; j < _grid.getHeight(); j += 16) {
_grid.getPatch(i + 1, j + 0).setState(1);
_grid.getPatch(i + 2, j + 1).setState(1);
_grid.getPatch(i + 2, j + 2).setState(1);
_grid.getPatch(i + 1, j + 2).setState(1);
_grid.getPatch(i + 0, j + 2).setState(1);
}
}
while (true) { while (true) {
_grid = Conway.run(_grid); _grid = Conway.run(_grid);
@@ -26,9 +30,9 @@ public class Goldfish {
_render.run(); _render.run();
_render.sleep(); _render.sleep();
} }
}
}
public static void main (String[] args) {
public static void main(String[] args) {
Goldfish g = new Goldfish(); Goldfish g = new Goldfish();
g.run(); g.run();
} }


+ 5
- 7
src/Render.java View File

@@ -128,8 +128,11 @@ public class Render extends Canvas implements Runnable, MouseListener,
@Override @Override
public void mouseDragged(MouseEvent e) { public void mouseDragged(MouseEvent e) {
_grid.getPatch(e.getX() / scale, e.getY() / scale).setState(1);
draw(e.getX() / scale, e.getY() / scale, 0xffffff);
try {
_grid.getPatch(e.getX() / scale, e.getY() / scale).setState(1);
draw(e.getX() / scale, e.getY() / scale, 0xffffff);
} catch (ArrayIndexOutOfBoundsException exception) {
}
e.consume(); e.consume();
} }
@@ -139,26 +142,21 @@ public class Render extends Canvas implements Runnable, MouseListener,
@Override @Override
public void mouseEntered(MouseEvent e) { public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
} }
@Override @Override
public void mouseExited(MouseEvent e) { public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
} }
@Override @Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
} }
@Override @Override
public void mouseReleased(MouseEvent e) { public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
} }
@Override @Override
public void mouseMoved(MouseEvent e) { public void mouseMoved(MouseEvent e) {
// TODO Auto-generated method stub
} }
} }

Loading…
Cancel
Save