-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfaceLife.cpp
More file actions
117 lines (83 loc) · 2.72 KB
/
faceLife.cpp
File metadata and controls
117 lines (83 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// AppLife.cpp
//*********************************************************************************************************
//* Edit History, started June, 2011
//* please put your initials and comments here anytime you make changes
//*********************************************************************************************************
//* Jun 20, 2011 (rp) added random color to "case 3";
//* QVS moved to wiserclock format
//*********************************************************************************************************
#include "faceLife.h"
#include "HT1632.h"
int Generations = 0;
#define GEN 200
void LifeFace::init()
{
// start a new game of life (from a newly generated patern);
// Serial.begin(9600);
Generations = 0;
}
void LifeFace::updateDisplay()
{
byte x,y;
if (Generations-- == 0) {
char timeBuffer[6];
timeBuffer[0] = (hours < 10) ? ' ' : ('0' + hours/10);
timeBuffer[1] = '0' + hours % 10;
timeBuffer[2] = ':';
timeBuffer[3] = '0' + minutes / 10;
timeBuffer[4] = '0' + minutes % 10;
timeBuffer[5] = 0;
//randomText[0] = random(32, 127);
//randomText[1] = random(32, 127);
//randomText[2] = random(32, 127);
displayStaticLine(timeBuffer, 1, GREEN);
delay(1000);
Generations = GEN;
}
snapshot_shadowram();
for (x=0; x < X_MAX; x++)
{
byte xabove = (x == X_MAX-1) ? 0 : x+1;
byte xbelow = (x == 0) ? X_MAX-1 : x-1;
for (y=0; y < Y_MAX; y++)
{
byte neighbors = 0;
byte yabove = (y == Y_MAX-1) ? 0 : y+1;
byte ybelow = (y == 0) ? Y_MAX-1 : y-1;
if (get_snapshotram(x, yabove) > 0) neighbors++;
if (get_snapshotram(x, ybelow) > 0) neighbors++;
if (get_snapshotram(xabove, y) > 0) neighbors++;
if (get_snapshotram(xabove, yabove) > 0) neighbors++;
if (get_snapshotram(xabove, ybelow) > 0) neighbors++;
if (get_snapshotram(xbelow, y) > 0) neighbors++;
if (get_snapshotram(xbelow, yabove) > 0) neighbors++;
if (get_snapshotram(xbelow, ybelow) > 0) neighbors++;
byte newval = get_snapshotram(x,y);
switch (neighbors)
{
// Conditions picked up by default...
// case 0:
// case 1:
// newval = BLACK; // death by loneliness
// break;
case 2:
if (newval != BLACK)
newval = ORANGE;
break; // remains the same
case 3:
// newval = random(GREEN, ORANGE + 1);
if (newval == BLACK)
newval = GREEN;
else
newval = RED;
break;
default:
newval = BLACK; // death by overcrowding
break;
}
ht1632_plot(x,y, newval);
}
}
snapshot_shadowram();
delay(800);
}