// 竖向 static void display1(int x, int y, unsigned char* lattice, int width, int height) { char tmp = 0; for (int i = 0; i < width; i++) { // 显示一列 for (int j = 0; j < height; j++) { tmp = lattice[j * width + i]; if (tmp & 0x01) pixel(x + i, y + j, 0xffffff); //Sleep(10); //myrefresh(); } Sleep(30); myrefresh(); } myrefresh(); }
void one_iter() { static int start, end, row, diff, flag = 0, direction; do { start = rand() % (COLS - 3); end = rand() % (COLS - 3); start = (start < 2) ? 2 : start; end = (end < 2) ? 2 : end; direction = (start > end) ? -1 : 1; diff = abs(start - end); } while (diff < 2 || diff >= LINES - 2); attrset(A_NORMAL); for (row = 0; row < diff; row++) { mvaddstr(LINES - row, row * direction + start, (direction < 0) ? "\\" : "/"); if (flag++) { myrefresh(); erase(); flag = 0; } } if (flag++) { myrefresh(); flag = 0; } explode(LINES - row, diff * direction + start); erase(); myrefresh(); }
void explode(int row, int col) { erase(); mvaddstr(row, col, "-"); myrefresh(); --col; get_color(); mvaddstr(row - 1, col, " - "); mvaddstr(row, col, "-+-"); mvaddstr(row + 1, col, " - "); myrefresh(); --col; get_color(); mvaddstr(row - 2, col, " --- "); mvaddstr(row - 1, col, "-+++-"); mvaddstr(row, col, "-+#+-"); mvaddstr(row + 1, col, "-+++-"); mvaddstr(row + 2, col, " --- "); myrefresh(); get_color(); mvaddstr(row - 2, col, " +++ "); mvaddstr(row - 1, col, "++#++"); mvaddstr(row, col, "+# #+"); mvaddstr(row + 1, col, "++#++"); mvaddstr(row + 2, col, " +++ "); myrefresh(); get_color(); mvaddstr(row - 2, col, " # "); mvaddstr(row - 1, col, "## ##"); mvaddstr(row, col, "# #"); mvaddstr(row + 1, col, "## ##"); mvaddstr(row + 2, col, " # "); myrefresh(); get_color(); mvaddstr(row - 2, col, " # # "); mvaddstr(row - 1, col, "# #"); mvaddstr(row, col, " "); mvaddstr(row + 1, col, "# #"); mvaddstr(row + 2, col, " # # "); myrefresh(); }
// 横向 static void display(int x, int y, unsigned char* lattice, int width, int height) { char tmp = 0; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { //tmp = lattice[i * width + j]; tmp = *lattice++; if (tmp & 0x01) pixel(x + j, y + i, 0); else pixel(x + j, y + i, 0xffffff); //Sleep(10); //myrefresh(); } //Sleep(1000); //myrefresh(); } myrefresh(); }
int main(int argc, char **argv) { int i, start, end, row, diff, flag, direction, seed; #ifdef XCURSES Xinitscr(argc, argv); #else initscr(); #endif nodelay(stdscr, TRUE); noecho(); if (has_colors()) start_color(); for (i = 0; i < 8; i++) init_pair(i, color_table[i], COLOR_BLACK); seed = time((time_t *)0); srand(seed); flag = 0; while (getch() == ERR) /* loop until a key is hit */ { do { start = rand() % (COLS - 3); end = rand() % (COLS - 3); start = (start < 2) ? 2 : start; end = (end < 2) ? 2 : end; direction = (start > end) ? -1 : 1; diff = abs(start - end); } while (diff < 2 || diff >= LINES - 2); attrset(A_NORMAL); for (row = 0; row < diff; row++) { mvaddstr(LINES - row, row * direction + start, (direction < 0) ? "\\" : "/"); if (flag++) { myrefresh(); erase(); flag = 0; } } if (flag++) { myrefresh(); flag = 0; } explode(LINES - row, diff * direction + start); erase(); myrefresh(); } endwin(); return 0; }