Skip to content

Instantly share code, notes, and snippets.

@shioken
Last active December 14, 2016 09:48
Show Gist options
  • Save shioken/4d007090fa24ec5d7c0ce8b934b5f9ba to your computer and use it in GitHub Desktop.
Save shioken/4d007090fa24ec5d7c0ce8b934b5f9ba to your computer and use it in GitHub Desktop.
Processing Lifegame Grayscale
void setup() {
size(800, 800);
colorMode(RGB, 1.0);
init();
}
static final int SIZE = 100;
float map[][] = new float[SIZE * SIZE][2];
int current;
void init() {
current = 0;
for (int i = 0; i < SIZE * SIZE; i++) {
map[i][current] = random(1);
}
}
void draw() {
background(0);
float unit = width / SIZE;
for (int i = 0; i < SIZE * SIZE; i++) {
int x = i % SIZE;
int y = i / SIZE;
fill(map[i][current]);
noStroke();
rect(x * unit, y * unit, unit, unit);
}
//saveFrame("line-####.png");
next();
}
void next() {
for (int i = 0; i < SIZE * SIZE; i++) {
float total = 0.0f;
int x = i % SIZE;
int y = i / SIZE;
for (int x1 = -1; x1 < 2; x1++) {
for (int y1 = -1; y1 < 2; y1++) {
if (x1 != 0 || y1 != 0) {
int tx = (x + x1 + SIZE) % SIZE;
int ty = (y + y1 + SIZE) % SIZE;
total += map[tx + ty * SIZE][current];
}
}
}
if (map[i][current] > 0.5) {
if (total < 2.0) {
map[i][1 - current] = map[i][current] * 0.5;
}
else if (total < 4.0) {
map[i][1 - current] = map[i][current] * 1.05;
}
else {
map[i][1 - current] = map[i][current] * 0.2;
}
}
else {
if (total < 2.0) {
map[i][1 - current] = map[i][current] * 0.9;
}
else if (total < 6.0) {
map[i][1 - current] = map[i][current] * 1.1;
}
else {
map[i][1 - current] = map[i][current] * 0.9;
}
}
map[i][1 - current] = min(max(0.0, map[i][1 - current]), 1);
}
current = 1 - current;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment