Created
April 3, 2020 18:53
-
-
Save RemyPorter/49d600d3a40084975ebcfda9c0a1336f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ch.bildspur.postfx.builder.*; | |
import ch.bildspur.postfx.pass.*; | |
import ch.bildspur.postfx.*; | |
PostFX fx; | |
final int EMPTY = 0; | |
final int CELL = 1; | |
final int DECAY = 2; | |
final int RELAPSE = 3; | |
final int[] colors = { | |
#000000, | |
#EEFFEE, | |
#7F887F, | |
#222255 | |
}; | |
int PLAYFIELD_SIZE = 200; | |
int[][] playfield = new int[PLAYFIELD_SIZE][PLAYFIELD_SIZE]; | |
int[] neighborhood = {-1, 0, 1}; | |
int countInNeighborhood(int x, int y, int[][] playfield, int value) { | |
int res = 0; | |
for (int i : neighborhood) { | |
for (int j : neighborhood) { | |
if (x+i < 0 || x+i >= PLAYFIELD_SIZE || y+j < 0 || y+j >= PLAYFIELD_SIZE) continue; | |
if (playfield[x+i][y+j] == value) res++; | |
} | |
} | |
return res; | |
} | |
void drawCell(int x, int y, int value) { | |
noStroke(); | |
fill(colors[value]); | |
rect(x, y, 1, 1); | |
} | |
void evaluateCell(int x, int y, int[][] playfield, int[][] nextField) { | |
switch(playfield[x][y]) { | |
case EMPTY: | |
if (countInNeighborhood(x, y, playfield, CELL) > 1 | |
&& countInNeighborhood(x, y, playfield, CELL) < 4) { | |
nextField[x][y] = CELL; | |
} | |
break; | |
case CELL: | |
if (countInNeighborhood(x, y, playfield, CELL) > 3 | |
&& countInNeighborhood(x, y, playfield, CELL) < 5) { | |
nextField[x][y] = CELL; | |
} else { | |
nextField[x][y] = DECAY; | |
} | |
break; | |
case DECAY: | |
if (countInNeighborhood(x, y, playfield, CELL) > 3) { | |
nextField[x][y] = DECAY; | |
} else { | |
nextField[x][y] = RELAPSE; | |
} | |
break; | |
} | |
} | |
void setup() { | |
size(1080, 1080, P3D); | |
for (int i = 0; i < PLAYFIELD_SIZE; i++) { | |
for (int j = 0; j < PLAYFIELD_SIZE; j++) { | |
playfield[i][j] = EMPTY; | |
} | |
} | |
int cx, cy; | |
cx = PLAYFIELD_SIZE/2; | |
cy = PLAYFIELD_SIZE/2; | |
playfield[cx][cy] = CELL; | |
playfield[cx-1][cy] = CELL; | |
playfield[cx+1][cy] = CELL; | |
//playfield[cx][cy-1] = CELL; | |
frameRate(30); | |
fx = new PostFX(this); | |
} | |
void step() { | |
int[][] next = new int[PLAYFIELD_SIZE][PLAYFIELD_SIZE]; | |
for (int i = 0; i < PLAYFIELD_SIZE; i++) { | |
for (int j = 0; j < PLAYFIELD_SIZE; j++) { | |
evaluateCell(i, j, playfield, next); | |
} | |
} | |
playfield = next; | |
} | |
void keyPressed() { | |
step(); | |
} | |
void draw() { | |
step(); | |
clear(); | |
scale(((float)width)/PLAYFIELD_SIZE, ((float)height)/PLAYFIELD_SIZE); | |
for (int i = 0; i < PLAYFIELD_SIZE; i++) { | |
for (int j = 0; j < PLAYFIELD_SIZE; j++) { | |
drawCell(i, j, playfield[i][j]); | |
} | |
} | |
fx.render() | |
.blur(4, 0.5) | |
.pixelate(PLAYFIELD_SIZE*2) | |
.bloom(0.1, 5, 0.5) | |
.rgbSplit(20) | |
.compose(); | |
saveFrame("ships/####.tiff"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment