Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jmash committed Feb 6, 2017
0 parents commit b172448
Show file tree
Hide file tree
Showing 13 changed files with 1,534 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
node_modules

# testing
coverage

# production
build

# misc
.DS_Store
.env
npm-debug.log
1,244 changes: 1,244 additions & 0 deletions README.md

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "ConwayGOL",
"version": "0.1.0",
"private": true,
"devDependencies": {
"react-scripts": "0.8.5"
},
"dependencies": {
"react": "^15.4.2",
"react-dom": "^15.4.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
Binary file added public/favicon.ico
Binary file not shown.
31 changes: 31 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tag above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start`.
To create a production bundle, use `npm run build`.
-->
</body>
</html>
Empty file added src/Components/App.css
Empty file.
13 changes: 13 additions & 0 deletions src/Components/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React, { Component } from 'react';
import ControlPanel from './ControlPanel';
import './App.css';

class App extends Component {
render() {
return (
<ControlPanel />
);
}
}

export default App;
8 changes: 8 additions & 0 deletions src/Components/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
});
89 changes: 89 additions & 0 deletions src/Components/ControlPanel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import React, { Component } from 'react';
import Grid from './Grid';

export default class ControlPanel extends Component {
constructor(props) {
super(props);

this.state = {
gridSizeX: 30,
gridSizeY: 30,
cellSize: 25,
};
}

handleCellSize = (e) => {
this.setState({ cellSize: Number(e.target.value) })
};



render() {
const styles = {
viewport: {

},
controlpanel: {
height:70,
width:"100%",
background:"grey",
opacity:"0.7",
top:0,
},
title: {
margin:0,
fontSize:"1em",
top:0,
},
options: {
marginLeft:"auto",
marginRight:"auto",
marginTop:0,
marginBottom:0,
textAlign:"center",
},
buttonSection: {
display:"inline-block"
},
slidersSection: {
display:"inline-block"
},
options_h3: {
margin:0,
}
}
return (
<div style={ styles.viewport }>
<div style={ styles.controlpanel }>
<h1 style={ styles.title }>Conways Game of Life (logo incoming)</h1>
<div style={ styles.options }>
<h3 style={ styles.options_h3 }>Controls</h3>
<div style={ styles.buttonSection }>
<button>Run</button>
<button>Next</button>
<button>Reset</button>
<button>Randomize</button>
</div>
<div style={ styles.slidersSection }>
<input
type={ "range" }
name={ "cellSize" }
id={ "cellSize" }
value={ this.state.cellSize }
min={10}
max={30}
onChange={ this.handleCellSize }
step={ 1 }
/>
</div>
</div>
</div>
<Grid
gridSizeX={ this.state.gridSizeX }
gridSizeY={ this.state.gridSizeY }
cellSize={ this.state.cellSize }
/>
</div>
);
}
}
69 changes: 69 additions & 0 deletions src/Components/Grid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React, { Component } from 'react';
import GridCell from './GridCell';

export default class Grid extends Component {
constructor(props) {
super(props);

this.state = {
lifeGrid: (function(gridSizeX, gridSizeY) {
const xs = new Array(gridSizeX).fill({life: "alive"});
const ys = new Array(gridSizeY).fill(xs);
return ys;
})(this.props.gridSizeX, this.props.gridSizeY)
}
}

handleCellClick = (e) => {
console.log(e);
}

updateGrid() {

}

render() {
// console.log(this.state.lifeGrid[0][0].life);
const styles = {
grid: {
textAlign:"center",
height:this.props.cellSize,
},
row: {
height:this.props.cellSize,
},
alive: {
background:"red",
},
dead: {
background:"white",
}
};

const x = this.props.gridSizeX;
const y = this.props.gridSizeY;

var rows = [];
for (let i = 0; i < Number(x); i++) {
var cells = [];
for (let j = 0; j < Number(y); j++) {
cells.push(<GridCell key={ i + "_" + j }
id={ i + "_" + j }
x={ i }
y={ j }
cellSize={ this.props.cellSize }
life={ (this.state.lifeGrid[i][j].life === "dead") ? styles.dead : styles.alive }
onClick={ this.handleCellClick.bind(this) }
/>)
}
var row = React.createElement('div', { style: styles.row, key: i }, cells);
// console.log(row);
rows.push(row);
}
// console.log(rows);
return (
<div style={ styles.grid }>{ rows }</div>
)

}
}
31 changes: 31 additions & 0 deletions src/Components/GridCell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, { Component } from 'react';

export default class GridCell extends Component {
// constructor(props) {
// super(props);
// }

render() {
const styles = {
cell: {
borderStyle: "solid",
borderColor: "black",
borderWidth: "1px",
height:this.props.cellSize,
width:this.props.cellSize,
display:"inline-block"
},
alive: {
background:"red",
},
dead: {
background:"white",
},
}

// console.log(this.props.id);
return (
<div style={ styles.cell (this.props.life === "dead") ? styles.dead : styles.alive }></div>
);
}
}
7 changes: 7 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
body {
margin: 0;
padding: 0;
font-family: sans-serif;
width:100%;
height:100%;
}
9 changes: 9 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './Components/App';
import './index.css';

ReactDOM.render(
<App />,
document.getElementById('root')
);

0 comments on commit b172448

Please sign in to comment.