//wireworld.c - doodle77 10-10-07 #include #include #include void setColor( int color ) { HANDLE hOut = GetStdHandle( STD_OUTPUT_HANDLE ); SetConsoleTextAttribute( hOut, color ); } void setCursorPos( int x, int y ) { HANDLE hOut = GetStdHandle( STD_OUTPUT_HANDLE ); COORD coord; coord.X = x; coord.Y = y; SetConsoleCursorPosition( hOut, coord ); } void clearScreen() { HANDLE hOut = GetStdHandle( STD_OUTPUT_HANDLE ); COORD coord = {0,0}; DWORD consoleSize; FillConsoleOutputCharacter( hOut, ' ', 65536, coord, &consoleSize ); FillConsoleOutputAttribute(hOut,0x07,consoleSize,coord,&consoleSize); SetConsoleCursorPosition( hOut, coord ); } //NOTE: FRAMEDATA NEEDS PADDING AROUND EDGES (edges should all be blank) void run_wireworld(char* oldframedata, char* newframedata, int width, int height) { int x,y; for (x=width;x!=0;x--) { // i'm doing this backwards for almost no reason (jnz?) for (y=height;y!=0;y--) { switch (oldframedata[width*y+x]) { case 0: //blank - assume the frame is empty (or filled with an old frame's data) break; case 3: { //copper int k = (oldframedata[width*y+x+1] == 1) + (oldframedata[width*y+x-1] == 1) + (oldframedata[width*(y+1)+x] == 1) + (oldframedata[width*(y-1)+x] == 1) + (oldframedata[width*(y-1)+x-1] == 1) + (oldframedata[width*(y+1)+x-1] == 1) + (oldframedata[width*(y-1)+x+1] == 1) + (oldframedata[width*(y+1)+x+1] == 1); if (k == 2 || k == 1) newframedata[width*y+x] = 1; else newframedata[width*y+x] = 3; break; } case 1: //head newframedata[width*y+x] = 4; break; case 4: //tail newframedata[width*y+x] = 3; break; default: printf("%d,%d,%d\n",x,y,oldframedata[width*y+x]); } } } } #define FRAME_WIDTH 10 #define FRAME_HEIGHT 10 // 0 1 2 3 4 5 6 7 8 9 char frame[FRAME_WIDTH*FRAME_HEIGHT] = {0,0,0,0,0,0,0,0,0,0, //0 0,0,0,0,0,0,0,0,0,0, //1 0,3,3,3,3,3,3,3,0,0, //2 0,0,0,0,0,0,0,0,3,0, //3 0,0,0,0,0,0,0,0,3,0, //4 0,0,0,3,3,3,3,0,3,0, //5 0,0,3,0,0,0,3,0,3,0, //6 0,0,0,3,4,1,0,3,0,0, //7 0,0,0,0,0,0,0,0,0,0, //8 0,0,0,0,0,0,0,0,0,0 //9 }; char frame2[FRAME_WIDTH*FRAME_HEIGHT]; void print_wireworld(char* framedata, int width, int height) { int x,y; clearScreen(); //setCursorPos(0,0); for (y=0;y