Class: ConwayWindow
- Inherits:
-
FXMainWindow
- Object
- FXMainWindow
- ConwayWindow
- Defined in:
- lib/conway_fx_gui.rb
Constant Summary collapse
- WIDTH =
769- HEIGHT =
430- GRIDSIZE =
25
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize(app) ⇒ ConwayWindow
constructor
A new instance of ConwayWindow.
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 = "Conway's Game Of Life is a cellular automaton originally conceived by \nJohn Conway in the early 1970's.\n\nUse the mouse to interactively define a starting grid by clicking on\ncells in the grid to bring them to life. Clicking on a cell toggles its\nlive state. Click and drag to bring a bunch of cells to life. Live \ncells are represented with green circles.\n\nThe rules of evolution are as follows:\n\n- If a live cell has more than 3 live neighbors, it dies from overcrowding\n- If a live cell has fewer than 2 live neighbors, it dies from loneliness\n- If a dead cell has exactly 3 live neighbors, it comes to life\n\nClick the \\\"Evolve\\\" button to iterate through generations one at a time.\nClick the \"Clear\" button to clear the grid.\n" FXLabel.new(rightFrame, desc, nil, JUSTIFY_LEFT) = FXHorizontalFrame.new(rightFrame, LAYOUT_SIDE_TOP|LAYOUT_SIDE_RIGHT|LAYOUT_FILL_Y) nextGenerationButton = FXButton.new(, "&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(, "&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(, "&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
#create ⇒ Object
71 72 73 74 |
# File 'lib/conway_fx_gui.rb', line 71 def create super show(PLACEMENT_SCREEN) end |