Class: ConwayWindow

Inherits:
FXMainWindow
  • Object
show all
Defined in:
lib/conway_fx_gui.rb

Constant Summary collapse

WIDTH =
769
HEIGHT =
430
GRIDSIZE =
25

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ConwayWindow

Returns a new instance of ConwayWindow.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/conway_fx_gui.rb', line 10

def initialize(app)
  super(app, "RLife - Conways Game Of Life", nil, nil, DECOR_TITLE | DECOR_BORDER | DECOR_CLOSE |LAYOUT_FILL_X|LAYOUT_FILL_Y, 0, 0, WIDTH, HEIGHT)
  FXToolTip.new(app)
  FXStatusBar.new(self, LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X)
  @cell_grid = CellGrid.new(16, 16)
  
  rightFrame = FXVerticalFrame.new(self,LAYOUT_SIDE_TOP|LAYOUT_SIDE_RIGHT|LAYOUT_FILL_Y)
  desc = <<EOS
Conway's Game Of Life is a cellular automaton originally conceived by 
John Conway in the early 1970's.

Use the mouse to interactively define a starting grid by clicking on
cells in the grid to bring them to life. Clicking on a cell toggles its
live state.  Click and drag to bring a bunch of cells to life.  Live 
cells are represented with green circles.

The rules of evolution are as follows:

- If a live cell has more than 3 live neighbors, it dies from overcrowding
- If a live cell has fewer than 2 live neighbors, it dies from loneliness
- If a dead cell has exactly 3 live neighbors, it comes to life

Click the \"Evolve\" button to iterate through generations one at a time.
Click the "Clear" button to clear the grid.
EOS
  FXLabel.new(rightFrame, desc, nil, JUSTIFY_LEFT)
  buttonFrame = FXHorizontalFrame.new(rightFrame,
                                      LAYOUT_SIDE_TOP|LAYOUT_SIDE_RIGHT|LAYOUT_FILL_Y)
  nextGenerationButton = FXButton.new(buttonFrame,
                                      "&Evolve\tEvolve The System\tEvolve The System",
                                      nil, nil, 0,FRAME_RAISED|FRAME_THICK|LAYOUT_FIX_WIDTH|LAYOUT_FIX_HEIGHT,0, 0,
                                      70, 30)
  clearButton = FXButton.new(buttonFrame,
                             "&Clear\tClear all live cells\tClear all live cells",
                             nil, nil, 0,FRAME_RAISED|FRAME_THICK|LAYOUT_FIX_WIDTH|LAYOUT_FIX_HEIGHT,0, 0,
                             70, 30)
  quitButton = FXButton.new(buttonFrame,
                            "&Quit\tExit the Program\tExit the Program",
                            nil, nil, 0,FRAME_RAISED|FRAME_THICK|LAYOUT_FIX_WIDTH|LAYOUT_FIX_HEIGHT,0, 0,
                            70, 30)
  canvasFrame = FXVerticalFrame.new(self,
                                    FRAME_RIDGE|LAYOUT_FILL_X|LAYOUT_FILL_Y|
                                    LAYOUT_TOP|LAYOUT_LEFT,
                                    0, 0, 0, 0, 0,0,0,0)
  @canvas = GridCanvas.new(canvasFrame, @cell_grid)
  
  quitButton.connect(SEL_COMMAND) {
    getApp().exit(0)
  }
  
  nextGenerationButton.connect(SEL_COMMAND) {
    @cell_grid.evolve
    @canvas.draw_grid
  }
  
  clearButton.connect(SEL_COMMAND) {
    @cell_grid.kill_all
    @canvas.draw_grid
  }
end

Instance Method Details

#createObject



71
72
73
74
# File 'lib/conway_fx_gui.rb', line 71

def create
  super
  show(PLACEMENT_SCREEN)
end