void ConstrainRect::GetCurrent (Coord& l, Coord& b, Coord& r, Coord& t) { if (trackx > fixedx && tracky > fixedy) { NorthEast(trackx, tracky); } else if (trackx > fixedx && tracky < fixedy) { SouthEast(trackx, tracky); } else if (trackx < fixedx && tracky > fixedy) { NorthWest(trackx, tracky); } else { SouthWest(trackx, tracky); } RubberRect::GetCurrent(l, b, r, t); }
/* compute the next generation of the world */ void NextGeneration(char **oldWorld, char **newWorld, int row, int column) { //RULES: //Live cell fewer than 2 live neighbours dies //Live Cell more than 3 live neigbours dies //Live cell 2 or 3 neigbours lives //Dead cell with 3 neigbours becomes alive. //primitives int i, j; int neigbours = 0; //loop through visible non border region //CHECK for (i = 0; i < row; i++) { for (j = 0; j < column; j++) { neigbours = 0; //sum up the neigbours neigbours += North(oldWorld, i, j, row, column); neigbours += NorthEast(oldWorld, i, j, row, column); neigbours += NorthWest(oldWorld, i, j, row, column); neigbours += South(oldWorld, i, j, row, column); neigbours += SouthEast(oldWorld, i, j, row, column); neigbours += SouthWest(oldWorld, i, j, row, column); neigbours += East(oldWorld, i, j, row, column); neigbours += West(oldWorld, i, j, row, column); //check for the rules above //check if the cell is alive if (LiveCell(oldWorld, i, j) == TRUE) { //Live cell fewer than 2 live neighbours dies if (neigbours < 2) { newWorld[i][j]=' '; //DEBUG //printf("\n\nIt's Dead\n"); } //Live Cell more than 3 live neigbours dies else if (neigbours > 3) { newWorld[i][j]=' '; //printf("\n\nIt's Dead\n"); } //Live cell 2 or 3 neigbours lives //this is redundant since it will stay alive } else //Dead cell with 3 neigbours becomes alive. if (neigbours == 3) { //It shall be reborn! newWorld[i][j]='x'; } } } }