Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <div id="render-target"></div>
            
          
!

CSS

            
              .myTitle {
  color: white;
  text-align: center;
  background-color: #ff1744;
  margin-top: 0;
  padding-top: 3%;
  padding-bottom: 1%;
  margin-bottom: 0;
}

.game {
  background-color: white;
  height: 640px;
  margin-bottom: 3%;
}
.fooTitle {
  text-align: center;
  color: white;
}
.foot {
  background-color: #ff1744;
  margin-top: 0;
  padding-top: 2%;
  padding-bottom: 2%;
  margin-bottom: 0;

}
.collect {
  background-color: #ef5350;
}
.collect > ul {
  background-color: #ef5350;
  border-color: white;
}
.collection-item {
  background-color: #ef5350 !important;
  border-width: 0 !important;
}
.buttons {
  margin-top: 2%;
}
.cpright {
  text-align: center;
  background-color: #ef5350;
  margin: 0;
  padding-bottom: 1%;
  padding-top: 1%;
  font-size: 1.2em;
  color: white;
}
.game-board {
  width: 810px;
  height: 510px;
  background-color: black;
  line-height: 0;
  border-radius: 5px;
  border-width: 5px;
  border-color: #FF1447;
  border-style: solid;
  font-size: 0 !important;
  padding: 0;
}
.cell{
    box-shadow: inset 1px 1px 1px 1px white;
    background-color: black;
    width: 20px !important;
    height: 20px !important;
    display: inline-block;
    cursor: pointer;
}
.active {
  background-color: #ff1744;
}
.generations {
  border-radius: 2px;
  margin-bottom: 2%;
  padding-bottom: -2px;
  color: white;
  width: 810px;
}
            
          
!

JS

            
              

class App extends React.Component {
  constructor(props) { 
    super(props)
  }
  render() { 
  
  return (
    <div>
    <Title />
    <Game />
    <Footer />
    </div>
  );
  }
}

class Cells extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      active: false,
      nextState: false
    };
    this.activate = this.activate.bind(this);
  }
  calcNextMove() {
  }
  makeNextMove() {
    this.setState({active: this.state.nextState});
  }
  componentDidMount () {
    
  }
  activate() {
    let currentState = this.state.active;
    currentState = !currentState;
    this.setState({active:currentState});
    this.props.birth(this.props.id);
  }
  render() {
    return (<div onClick={this.activate} className={this.state.active?"cell active":"cell"}></div>);
  }
}



class Game extends React.Component {
  constructor(props) { 
    super(props)
    this.birth = this.birth.bind(this);
    var cell = [];
    var lifeArray = []
    for (var i = 1; i<=1000; i++) {
      cell.push(<Cells key={i} id={i} birth={this.birth} />);
      lifeArray.push(0);
    }
    this.state = ({
      cells: cell,
      lifeArray: lifeArray,
      gen: 0
    });
    
  }
  clear () {
    for (var i = 0; i < this.state.cells.length; i++) {
        var cell = this.state.cells[i];
        if (cell.hasOwnProperty("state")) {
          if (cell['state']['active'] == true) {
          cell.activate();
        }
      }
    }
  }
  birth(id) {
    let newState = this.state.lifeArray;
    newState[id] = 1;
    this.setState({ lifeArray: newState });
  }
  play () {

  }
  render() {
    return (
      <div className="game">
        <div className = "buttons container row">
          <a onClick={()=>this.play()} className="waves-effect waves-light btn red accent-3 col s3 offset-s1"><i className="material-icons right">play_arrow</i>Play</a>
          <a className="waves-effect waves-light btn red accent-3 col s3 offset-s1"><i className="material-icons right">pause</i>Pause</a>
          <a onClick={()=>this.clear()}className="waves-effect waves-light btn red accent-3 col s3 offset-s1"><i className="material-icons right">replay</i>Clear</a>
        </div>
        <h3 className="generations thin red accent-3 container">Generations: {this.state.gen} </h3>
         <div className="game-board container">
           {this.state.cells}
        </div>
      </div>
    );
  }
}

let Title = (props) => {
  return (
    <div>
    <h1 className="myTitle thin s12">John Conway's Game of Life </h1>
      </div>
  );
}

let Footer = (props) => {
  return(
    <div>
    <div className="foot row">
      <h4 className="thin fooTitle s12">Thanks for viewing my project!</h4>
      <div className="container">
      <div className="col s6">
        <div className="card red lighten-1">
            <div className="card-content white-text">
              <span className="card-title">About FreeCodeCamp</span>
              <p>FreeCodeCamp is a non-profit organization that hosts a multitude of coding challenges and projects for beginner to advanced programmers for absolutely free.</p>
            </div>
            <div className="card-action">
              <a href="https://www.freecodecamp.org/about/" target="_blank">Find out more</a>
            </div>
      </div>
      </div>
      <div className="col s6 collect">
      <ul className="collection">
        <h5 className="fooTitle">Nick Janne(Creator)</h5>
    <li className="collection-item avatar">
      <img src="https://assets-cdn.github.com/images/modules/logos_page/GitHub-Mark.png" alt="Github" className="circle"/>
      <a href="https://github.com/njanne19"target="_blank"className="av-button red accent-3 waves-effect waves-light btn">Github</a>
    </li>
    <li className="collection-item avatar">
      <img src="https://marks-playroom.co.uk/wp-content/uploads/2014/06/codepen.jpg" alt="Codepen" className ="circle" />
      <a href="codepen.io/njanne19/" target="_blank"className="av-button red accent-3 waves-effect waves-light btn">Codepen</a>
    </li>
    <li className="collection-item avatar">
      <img src="https://avatars2.githubusercontent.com/u/9892522?v=3&s=400" alt="FCC" className="circle" />
      <a href="https://www.freecodecamp.org/njanne19" target="_blank"className="av-button red accent-3 waves-effect waves-light btn">FreeCodeCamp</a>
    </li>
  </ul>
      </div>
      </div>
      </div>
      <p className="cpright light">Copyright Nick Janne &copy; 2017. All Rights Reserved</p>
      </div>
  );
}


$(document).ready(function() {
 ReactDOM.render(<App />, document.getElementById('render-target'));
 
});


            
          
!
999px

Console