simple-life.js
// Creates the next generation of cells
Creates the next generation of cells
Creates the next generation of cells
function step() {
    for (let i = 0; i < size; i++) {
        let neighbours = 0;
        for (let j of offset) {
            neighbours += at(i + j);
        }
        if ((state[i] == live)      && (neighbours < 2))  next[i] = dead;     
        else if ((state[i] == live) && (neighbours > 3))  next[i] = dead;     
        else if ((state[i] == dead) && (neighbours == 3)) next[i] = live;     
        else                                              next[i] = state[i]; 
    }
    let tmp = state;
    state = next;
    next = tmp;
}
function step ( ) { for ( let i = 0 ; i < size ; i ++ ) { let neighbours = 0 ; for ( let j of offset ) { neighbours += at ( i + j ) ; } if ( ( state [ i ] == live ) && ( neighbours < 2 ) ) next [ i ] = dead ; else if ( ( state [ i ] == live ) && ( neighbours > 3 ) ) next [ i ] = dead ; else if ( ( state [ i ] == dead ) && ( neighbours == 3 ) ) next [ i ] = live ; else next [ i ] = state [ i ] ; } let tmp = state ; state = next ; next = tmp ; }
Creates the next generation of cells
Creates the next generation of cells
// under-population // over-population // reproduction // stasis