| 21 | } |
| 22 | |
| 23 | void evolve(void *u, int w, int h) |
| 24 | { |
| 25 | unsigned (*univ)[w] = u; |
| 26 | unsigned new[h][w]; |
| 27 | |
| 28 | for_y for_x { |
| 29 | int n = 0; |
| 30 | for (int y1 = y - 1; y1 <= y + 1; y1++) |
| 31 | for (int x1 = x - 1; x1 <= x + 1; x1++) |
| 32 | if (univ[(y1 + h) % h][(x1 + w) % w]) |
| 33 | n++; |
| 34 | |
| 35 | if (univ[y][x]) n--; |
| 36 | new[y][x] = (n == 3 || (n == 2 && univ[y][x])); |
| 37 | } |
| 38 | for_y for_x univ[y][x] = new[y][x]; |
| 39 | } |
| 40 | |
| 41 | void nudge(void *u, int w, int h) |
| 42 | { |