make Game of Life with bigger pixels?
in
Programming Questions
•
1 year ago
I'm trying to edit this program so that the changing pixels are larger, but I'm not sure how
- int sx, sy;
- float density = 0.5;
- int[][][] world; //triple array
- void setup()
- {
- size(640, 500, P2D);
- frameRate(12); //set a framerate variable--1000/framerate = new variable called frameDuration
- sx = width;
- sy = height;
- world = new int[sx][sy][2];
- // Set random cells to 'on'
- for (int i = 0; i < sx * sy * density; i++) {
- world[(int)random(sx)][(int)random(sy)][1] = 1;
- }
- }
- void draw()
- {
- background(0);
- // Drawing and update cycle
- for (int x = 0; x < sx; x=x+1) {
- for (int y = 0; y < sy; y=y+1) {
- //if (world[x][y][1] == 1)
- // Change recommended by The.Lucky.Mutt
- if ((world[x][y][1] == 1) || (world[x][y][1] == 0 && world[x][y][0] == 1))
- {
- world[x][y][0] = 1;
- set(x, y, #FFFFFF);
- }
- if (world[x][y][1] == -1)
- {
- world[x][y][0] = 0;
- }
- world[x][y][1] = 0;
- }
- }
- // Birth and death cycle
- for (int x = 0; x < sx; x=x+1) {
- for (int y = 0; y < sy; y=y+1) {
- int count = neighbors(x, y);
- if (count == 3 && world[x][y][0] == 0) // if the cell is black and has three white neighbors
- {
- world[x][y][1] = 1;
- // audio here
- }
- if ((count < 2 || count > 3) && world[x][y][0] == 1) // if the cell is white and has less than 2 or more than 3 white neighbors
- {
- world[x][y][1] = -1;
- //audio here
- }
- }
- }
- }
- // differentiate between different coordinates on the grid
- // Count the number of adjacent cells 'on'
- int neighbors(int x, int y)
- {
- return world[(x + 1) % sx][y][0] +
- world[x][(y + 1) % sy][0] +
- world[(x + sx - 1) % sx][y][0] +
- world[x][(y + sy - 1) % sy][0] +
- world[(x + 1) % sx][(y + 1) % sy][0] +
- world[(x + sx - 1) % sx][(y + 1) % sy][0] +
- world[(x + sx - 1) % sx][(y + sy - 1) % sy][0] +
- world[(x + 1) % sx][(y + sy - 1) % sy][0];
- }
1