build/main.c
/*update the the grid following the 4 simple fundamental rules described by Conway
1) Any live cell with fewer than two live neighbors dies, as if caused by underpopulation.
2) Any live cell with more than three live neighbors dies, as if by overcrowding.
3) Any live cell with two or three live neighbors lives on to the next generation.
4) Any dead cell with exactly three live neighbors becomes a live cell.
*/
update the the grid following the 4 simple fundamental rules described by Conway
1) Any live cell with fewer than two live neighbors dies, as if caused by underpopulation.
2) Any live cell with more than three live neighbors dies, as if by overcrowding.
3) Any live cell with two or three live neighbors lives on to the next generation.
4) Any dead cell with exactly three live neighbors becomes a live cell.
update the the grid following the 4 simple fundamental rules described by Conway 1 ) Any live cell with fewer than two live neighbors dies as if caused by underpopulation . 2 ) Any live cell with more than three live neighbors dies as if by overcrowding . 3 ) Any live cell with two or three live neighbors lives on to the next generation . 4 ) Any dead cell with exactly three live neighbors becomes a live cell .
void evolve(struct argb8888 *grid){
	unsigned char temp[SCREEN_HEIGHT][SCREEN_WIDTH];
	int neighbors = 0;
	for (int i = 0; i < SCREEN_HEIGHT; i++){
		for (int j = 0; j < SCREEN_WIDTH; j++) {
			neighbors = 0;
			for(int i_test = i - 1; i_test <= i + 1; i_test++){
				for(int j_test = j - 1; j_test <= j + 1; j_test++){
					if(grid[((i_test + SCREEN_HEIGHT)%SCREEN_HEIGHT)*SCREEN_WIDTH + ((j_test + SCREEN_WIDTH) % SCREEN_WIDTH)].red){
						neighbors++;
					}
				}
			}
			if(grid[i*SCREEN_WIDTH + j].red){
				neighbors--;
			}
			temp[i][j] = (neighbors == 3 || (neighbors == 2 && grid[i*SCREEN_WIDTH + j].red));
		}
	}
	for(int i = 0; i < SCREEN_HEIGHT; i++){
		for(int j = 0; j < SCREEN_WIDTH; j++){
			grid[i * SCREEN_WIDTH + j].red = 255 * temp[i][j]; 
		}
	}
}
void evolve ( struct argb8888 * grid ) { unsigned char temp [ SCREEN_HEIGHT ] [ SCREEN_WIDTH ] ; int neighbors = 0 ; for ( int i = 0 ; i < SCREEN_HEIGHT ; i ++ ) { for ( int j = 0 ; j < SCREEN_WIDTH ; j ++ ) { neighbors = 0 ; for ( int i_test = i - 1 ; i_test <= i + 1 ; i_test ++ ) { for ( int j_test = j - 1 ; j_test <= j + 1 ; j_test ++ ) { if ( grid [ ( ( i_test + SCREEN_HEIGHT ) % SCREEN_HEIGHT ) * SCREEN_WIDTH + ( ( j_test + SCREEN_WIDTH ) % SCREEN_WIDTH ) ] . red ) { neighbors ++ ; } } } if ( grid [ i * SCREEN_WIDTH + j ] . red ) { neighbors -- ; } temp [ i ] [ j ] = ( neighbors == 3 || ( neighbors == 2 && grid [ i * SCREEN_WIDTH + j ] . red ) ) ; } } for ( int i = 0 ; i < SCREEN_HEIGHT ; i ++ ) { for ( int j = 0 ; j < SCREEN_WIDTH ; j ++ ) { grid [ i * SCREEN_WIDTH + j ] . red = 255 * temp [ i ] [ j ] ; } } }
update the the grid following the 4 simple fundamental rules described by Conway
1) Any live cell with fewer than two live neighbors dies, as if caused by underpopulation.
update the the grid following the 4 simple fundamental rules described by Conway 1 ) Any live cell with fewer than two live neighbors dies as if caused by underpopulation .
//holding aka boolean values for life or death in each pixel //reinitialize to zero for each outer iteration of the 3x3 grid testing //looking at a 3x3 grid checking for conditions //if value is positive then yes and update neighbors //update for correct calculation and application of rules, otherwise itself is counted unnecessarily //new life is created or extinguished by the rules and information stored in the temporal matrix //finally update grid for the new picture //either 255 or 0 //temp is either 0 or 1