#include #include #include #include #define MAX_BLOCKS 3000 #define MAX_ITERS 1000 #define ROW_LENGTH 100 #define U_SECONDS 50000 int main(void) { int x = 0, y = 0; bool stars[MAX_BLOCKS]; initscr(); cbreak(); noecho(); clear(); // Draw the initial field of dots. for (int i = 0; i < MAX_BLOCKS; i++) { stars[i] = false; mvaddch(y, x, '.'); if (++x == ROW_LENGTH) { x = 0; y++; } } refresh(); // Randomly flip blocks between dot and star. for (int i = 0; i < MAX_ITERS; i++) { int n = rand()%MAX_BLOCKS; stars[n] = !stars[n]; y = n/ROW_LENGTH; x = n%ROW_LENGTH; mvaddch(y, x, stars[n] ? '*' : '.'); refresh(); usleep(U_SECONDS); } mvaddstr(MAX_BLOCKS/ROW_LENGTH + 1, 0, "Press any key to quit"); refresh(); getch(); endwin(); exit(0); }