css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

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.

              <div ng-app="gameOfLifeApp" ng-controller="gameOfLifeCtrl"> 
  <h3 style="text-align: center">Game Of Life</h3>
  <h5 style="text-align: center"><a target="_blank" href="https://youtu.be/SL75BV9khkY">Video Tutorial</a></h5>
     <tr ng-repeat='row in rows'>
      <td ng-click=activate(rows.indexOf(row),$index) 
          ng-repeat='col in row.cols'
          ng-class="{'new':col.active == 1, 'old':col.active >1 }">        
   <div class="components">
   <button ng-click="stopGame();">stop</button>
   <button ng-click="startGame(false);">start</button>
   <button ng-click="clear();">clear</button>
   Generation: {{generation}}
  <div class="text-center" id="footer" style="text-align:center"> <!-- for footer -->
      <div class="col-xs-6">
      <h5><a href="http://www.eleftheriabatsou.com" target="_blank">Eleftheria</a> | <a href="https://codepen.io/EleftheriaBatsou" target="_blank">Projects</a> | <a href="https://www.youtube.com/channel/UCC-WwYv3DEW7Nkm_IP6VeQQ" target="_blank"> Coding videos </a></h5>
      <!-- social media -->
      <div class="col-xs-6 text-primary">
        <a href="https://twitter.com/BatsouElef" target="_blank">
     <img src="https://left.gr/sites/all/themes/newleft/images/socialicons/twitter.png" 
      style="text-align:center" alt="twitter"> 
         <a href="https://github.com/EleftheriaBatsou" target="_blank">
     <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSqSttU57LZvtB2Y77j2E2EkC6qgiTbYjVK75XU2SOzUXz2EFjX" 
      style="text-align:center" alt="github"> 
        <a href="https://www.youtube.com/channel/UCC-WwYv3DEW7Nkm_IP6VeQQ" target="_blank">
     <img id="footerSvg" src="https://image.flaticon.com/icons/svg/25/25312.svg" 
       style="text-align:center" alt="youtube"> 
    </div> <!-- end footer -->
              body{background-color: lightgray;}

table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
  margin: auto; 
  background-color: whitesmoke;}

  width: 15px;
  height: 15px;

.new{ background-color:orange; }
.old{ background-color: orangered; }

  margin: 20px auto 20px 30%;

a:link    {color:orangered;  text-decoration:none}
a:visited {color:orangered; text-decoration:none}
a:hover   {color:red; text-decoration:underline} 

  width: 32px;
              var app = angular.module('gameOfLifeApp', []);
app.controller('gameOfLifeCtrl', function($scope, $interval) {
  //grid size
  var rowMax = 25;
  var colMax = 30;
  // create grid
  $scope.rows = [];
  for(var i=0; i<rowMax; i++){
    var col = [];
    for(var j=0; j<colMax; j++){
      var elem = {'active': 0};
    $scope.rows.push({'cols': col});
  //generate seeds
  var randomSeeds = function(){
    for(var i=0; i<(rowMax*colMax/2); i++){
      var row = Math.floor(Math.random() * (rowMax -  1));
      var col = Math.floor(Math.random() * (colMax -  1));
  // count live neighbors
   var checkNeighbours = function(row, col){
     var count = 0;
     for(var i = row-1; i<=row+1; i++){
       for(var j= col-1; j<=col+1; j++){
         if((i!=row || j!=col) &&($scope.rows[i]) && ($scope.rows[i].cols[j]) ){
           if($scope.rows[i].cols[j].active >= 1){
     return count;
  $scope.stopGame = function(){
  $scope.activate = function(row, col){
    $scope.rows[row].cols[col].active = 1;
  var interval;
  $scope.startGame = function(random){
    $scope.generation = 0;
     interval = $interval(function(){
       for(var i=0; i<rowMax; i++){
         for(var j=0; j<colMax; j++){
           var noOfNeighbours = checkNeighbours(i,j);
           $scope.rows[i].cols[j].neighbours = noOfNeighbours;
       for(var i=0; i<rowMax; i++){
         for(var j=0; j<colMax; j++){
           if($scope.rows[i].cols[j].active >= 1){
             if($scope.rows[i].cols[j].neighbours >=4 || $scope.rows[i].cols[j].neighbours <=1){
               $scope.rows[i].cols[j].active = 0;
             if($scope.rows[i].cols[j].neighbours == 3){
               $scope.rows[i].cols[j].active = 1;
   }, 100);

  $scope.clear = function(){
    for(var i=0; i<rowMax; i++){
      for(var j=0; j<colMax; j++){
// board size
// optimize code please

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................