Skip to content

Commit

Permalink
If nothing has changed for a few cycles, reseed.
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Aug 30, 2013
1 parent 9bf17ae commit e9673ef
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/examples/LoLShield_Life/LoLShield_Life.pde
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ void setup() {
}

void loop() {
static byte boring = 0;
byte changed = 0;

// Birth and death cycle
for (byte x = 0; x < SIZEX; x++) {
for (byte y = 0; y < SIZEY; y++) {
Expand All @@ -56,9 +59,11 @@ void loop() {
if (count == 3 && !alive) {
// A new cell is born
alive = 1;
++changed;
} else if ((count < 2 || count > 3) && alive) {
// Cell dies
alive = 0;
++changed;
}
world[1][x][y] = alive;
}
Expand All @@ -71,9 +76,14 @@ void loop() {
}
}

if (changed)
boring = 0;
else
++boring;

//Counts and then checks for re-seeding
//Otherwise the display will die out at some point
if (++geck >= RESEEDRATE){
if (++geck >= RESEEDRATE || boring >= 5) {
geck = 0;
seedWorld();
}
Expand Down

0 comments on commit e9673ef

Please sign in to comment.