SM01-update

PHOTO EMBED

Mon Sep 18 2023 22:16:43 GMT+0000 (Coordinated Universal Time)

Saved by @yc_lan

void ofApp::update(){    

// Calculate the next generation based on the rules
    for (int i = 0; i < gridSize; i++) {
        for (int j = 0; j < gridSize; j++) {

            int neighbors = countNeighbors(i, j);

            if (grid[i][j]) {
                     nextGrid[i][j] = (neighbors == 2 || neighbors == 3);
                        // the same meaning ⬇️
//                       if (neighbors == 2 || neighbors == 3) {
//                           nextGrid[i][j] = true;
//                       } else {
//                           nextGrid[i][j] = false;
//                       }
                   } else {
                       nextGrid[i][j] = neighbors == 3;
                        // the same meaning ⬇️
//                       if (neighbors == 3) {
//                           nextGrid[i][j] = true;
//                       } else {
//                           nextGrid[i][j] = false;
//                       }
                   }
        }
    }


    // Copy the next generation to the current grid
    for (int i = 0; i < gridSize; i++) {
        for (int j = 0; j < gridSize; j++) {
            //update the changes to show them!
            grid[i][j] = nextGrid[i][j];
        }
    }
content_copyCOPY