-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLifeSimulation.java
More file actions
66 lines (54 loc) · 1.92 KB
/
LifeSimulation.java
File metadata and controls
66 lines (54 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
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
/**
* File: Cell.java
* Author: Jon Lee
* Date: 09/29/2018
* Class: CS231
*/
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Random;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JOptionPane;
public class LifeSimulation{
public static void main(String args[]) {
//Read the grid size and the number of time steps from the GUI
JOptionPane.showMessageDialog(null, "Welcome to Conway's Game of Life");
String inp = JOptionPane.showInputDialog("How big do you want your grid to be? 10 is a good size");
int size = Integer.parseInt(inp);
//Jpane to determine size
int rows;
int cols;
rows = Integer.parseInt(inp);
cols = Integer.parseInt(inp);
//how big do you want the size of the grid?
Landscape scape = new Landscape(size, size);
String inpu = JOptionPane.showInputDialog("How many time steps do you want? Please enter an integer. I'd say ~200 is appropriate to really visualize it");
int newInt = Integer.parseInt(inpu);
//random cell generator
Random random = new Random();
double dens = 0.4;
for (int i = 0; i < scape.getRows(); i++) {
for (int j = 0; j < scape.getCols(); j++ ) {
scape.getCell( i, j ).setAlive( random.nextDouble() <= dens );
}
}
LandscapeDisplay newDisplay = new LandscapeDisplay(scape, size);
newDisplay.repaint();
//however many times the user want to run this conway game of life.
for (int i = 0; i < newInt; i++){
scape.advance();
newDisplay.repaint();
newDisplay.saveImage( "data/life_frame_" + String.format( "%03d", i ) + ".png" );
}
}
}