Conway's Game of Life setup to run by itself on a Serial 4D Systems 3.2" LCD. Does not yet use the touch screen.
Revision 0:3e9d11eb5a2e, committed 2010-12-21
- Comitter:
- copperd
- Date:
- Tue Dec 21 23:38:22 2010 +0000
- Child:
- 1:714e68b0ba58
- Commit message:
- First public release
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/4DGL.lib Tue Dec 21 23:38:22 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Kerpower/code/4DGL/#2978d0ac4b79
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Dec 21 23:38:22 2010 +0000 @@ -0,0 +1,106 @@ +#include "mbed.h" +#include "TFT_4DGL.h" +unsigned short int displayold[26][35]; +unsigned short int displaynew[26][35]; +int sx,sy,clst,x,y,test,loops; +TFT_4DGL ecran(p9,p10,p11); // serial tx, serial rx, reset pin; + +int main() { + + srand(1); // Random seed + ecran.baudrate(115200); + ecran.background_color(WHITE); + ecran.pen_size(SOLID); + // Set up Grid + // Display field is 34 x 25 + y = 0; + x = 0; + for (sy = 1; sy <=34;sy++) + { + y=sy+1*sy*8; + ecran.line(9,y,233,y,BLUE); + y=(sy+1*sy*8)+8; + ecran.line(9,y,233,y,BLUE); + } + for (sx = 1; sx <=25;sx++) + { + x=sx+1*sx*8; + ecran.line(x,9,x,314,BLUE); + x=(sx+1*sx*8)+8; + ecran.line(x,9,x,314,BLUE); + } + + + + + + // forever run the next code to create a random field every 500 turns and play it out + while(1) + { + // Set up a random field and display + for (sy = 1; sy <= 34; sy++) + { + for (sx = 1; sx <= 25; sx++) + { + + if (rand()%10 == 4) + { + displayold[sx][sy] = 1; + ecran.rectangle(((9*sx)+1),((9*sy)+1),((9*sx)+7),((9*sy)+7),RED); + } + } + } + + // create new field from old field and run for 500 turns + for (loops = 0;loops <= 500; loops++) + { + for (sy = 1; sy <= 34; sy++) + { + for (sx = 1; sx <= 25; sx++) + { + + // Cheacking a block if its dead or alive then for neighbors and counting them and putting that in test + if (displayold[sx][sy] == 1) + { + test = displayold[sx-1][sy-1] + displayold[sx][sy-1] + displayold[sx+1][sy-1] + displayold[sx-1][sy] + displayold[sx+1][sy] + displayold[sx-1][sy+1] + displayold[sx][sy+1] + displayold[sx+1][sy+1]; + if (test == 2 || test == 3) + { + displaynew[sx][sy] = 1; + } + else displaynew[sx][sy] = 0; + } + else + { + test = displayold[sx-1][sy-1] + displayold[sx][sy-1] + displayold[sx+1][sy-1] + displayold[sx-1][sy] + displayold[sx+1][sy] + displayold[sx-1][sy+1] + displayold[sx][sy+1] + displayold[sx+1][sy+1]; + if (test == 3) + { + displaynew[sx][sy] = 1; + } + + } + + } + } + // Now we have a new field created we can update the squares only if they are differnt and move the new array to the old one + + for (sy = 1; sy <= 34; sy++) + { + for (sx = 1; sx <= 25; sx++) + { + if (displaynew[sx][sy] != displayold[sx][sy]) + { + displayold[sx][sy] = displaynew[sx][sy]; + if (displaynew[sx][sy] == 1) ecran.rectangle(((9*sx)+1),((9*sy)+1),((9*sx)+7),((9*sy)+7),RED); + else ecran.rectangle(((9*sx)+1),((9*sy)+1),((9*sx)+7),((9*sy)+7),WHITE); + + } + + + } + } + + + } + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Dec 21 23:38:22 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e