Difference between revisions of "CISC181 S2019 Lab3"
(→Instructions) |
|||
(One intermediate revision by the same user not shown) | |||
Line 16: | Line 16: | ||
** Here is some [https://drive.google.com/open?id=1UY2cywNpqZx270LkKWXmqtsf4Y_qziefegKv5IE3cuA example code shown in the March. 7 lecture]. You don't have to use it, but it demonstrates mouse interaction and timer events, plus contains the beginning of a button class that may be helpful | ** Here is some [https://drive.google.com/open?id=1UY2cywNpqZx270LkKWXmqtsf4Y_qziefegKv5IE3cuA example code shown in the March. 7 lecture]. You don't have to use it, but it demonstrates mouse interaction and timer events, plus contains the beginning of a button class that may be helpful | ||
− | For this exercise you will implement the "Game of Life", a cellular automaton on 2-D grid invented by mathematician John Conway in 1970. The update rules are as follows: | + | For this exercise you will implement the "Game of Life", a cellular automaton on 2-D grid invented by mathematician John Conway in 1970. There is a link to a web-based implementation [https://bitstorm.org/gameoflife/ here]. |
+ | |||
+ | The update rules are as follows: | ||
* For a space that is 'populated' | * For a space that is 'populated' | ||
Line 24: | Line 26: | ||
* For a space that is 'empty' or 'unpopulated', each cell with exactly three neighbors becomes populated | * For a space that is 'empty' or 'unpopulated', each cell with exactly three neighbors becomes populated | ||
− | + | Your implementation does not need to look like the web version above. Rather, at a minimum you must have the following features: | |
* At least 100 x 100 grid (larger window, of course) | * At least 100 x 100 grid (larger window, of course) | ||
Line 31: | Line 33: | ||
** You should provide at least "Clear" (revert grid to all empty), "Start" (begin running simulation steps automatically at some regular time interval), "Stop" (pause simulation animation), "Next" (take exactly one step of the simulation and show result) | ** You should provide at least "Clear" (revert grid to all empty), "Start" (begin running simulation steps automatically at some regular time interval), "Stop" (pause simulation animation), "Next" (take exactly one step of the simulation and show result) | ||
** Buttons that correspond to 4 or more common patterns (e.g., glider, exploder, tumbler). If you choose one of these, then click on the grid, the currently-selected pattern should be "dropped" at that location. Otherwise clicking on a grid square should toggle it from empty to full or back. | ** Buttons that correspond to 4 or more common patterns (e.g., glider, exploder, tumbler). If you choose one of these, then click on the grid, the currently-selected pattern should be "dropped" at that location. Otherwise clicking on a grid square should toggle it from empty to full or back. | ||
− | ** A "Random" button should randomly populate the entire grid with a well-chosen uniform probability | + | ** A "Random" button should randomly populate the entire grid with a well-chosen uniform probability |
===Finishing up=== | ===Finishing up=== | ||
Remember to use proper [https://google.github.io/styleguide/javaguide.html naming and formatting style] throughout your code, and submit your <tt>Lab3.java</tt> and <tt>LifeJComponent.java</tt> on Canvas by midnight (or just after) on '''Tuesday, March 12''' | Remember to use proper [https://google.github.io/styleguide/javaguide.html naming and formatting style] throughout your code, and submit your <tt>Lab3.java</tt> and <tt>LifeJComponent.java</tt> on Canvas by midnight (or just after) on '''Tuesday, March 12''' |
Latest revision as of 15:10, 8 March 2019
Preliminaries
This assignment continues our use of the Swing library for basic drawing, but also requires mouse interaction and timer events. For review, here again is the documentation for the JFrame, JComponent, Graphics, and Color classes. But also: MouseListener and Swing Timer.
Just like last time:
- Make a new project (but now n = 3) following these instructions.
- Name your class "Lab3". This happens when you are creating a new module, in the Java class name field
Instructions
Modify Lab3.java as you did last week:
- Add your name and your partner's name in a comment before the Lab3 class body, as well as before LifeJComponent
- Initialize a JFrame and custom LifeJComponent
- Here is some example code shown in the March. 7 lecture. You don't have to use it, but it demonstrates mouse interaction and timer events, plus contains the beginning of a button class that may be helpful
For this exercise you will implement the "Game of Life", a cellular automaton on 2-D grid invented by mathematician John Conway in 1970. There is a link to a web-based implementation here.
The update rules are as follows:
- For a space that is 'populated'
- Each cell with one or zero neighbors dies, as if from loneliness
- Each cell with four or more neighbors dies, as if by overpopulation
- Each cell with two or three neighbors survives
- For a space that is 'empty' or 'unpopulated', each cell with exactly three neighbors becomes populated
Your implementation does not need to look like the web version above. Rather, at a minimum you must have the following features:
- At least 100 x 100 grid (larger window, of course)
- The grid is on a torus (i.e., it wraps horizontally and vertically)
- No sliders or menus -- just buttons outside of grid area. Don't use JButtons -- just draw rectangles with explanatory labels (strings) and react to mouse clicks inside them.
- You should provide at least "Clear" (revert grid to all empty), "Start" (begin running simulation steps automatically at some regular time interval), "Stop" (pause simulation animation), "Next" (take exactly one step of the simulation and show result)
- Buttons that correspond to 4 or more common patterns (e.g., glider, exploder, tumbler). If you choose one of these, then click on the grid, the currently-selected pattern should be "dropped" at that location. Otherwise clicking on a grid square should toggle it from empty to full or back.
- A "Random" button should randomly populate the entire grid with a well-chosen uniform probability
Finishing up
Remember to use proper naming and formatting style throughout your code, and submit your Lab3.java and LifeJComponent.java on Canvas by midnight (or just after) on Tuesday, March 12