classMatrix { public: Matrix(int show_length = 9, int color = 0); ~Matrix(); boolRun(); boolShowColumn(int column); private: WINDOW* my_window; int row_recorder[2000]; int window_height; int window_width; int show_length; int color; };
boolMatrix::ShowColumn(int column){ int curr_row = 0; if(this->row_recorder[column] >= this->window_height + this->show_length) { curr_row = 0; this->row_recorder[column] = 0; } else { curr_row = this->row_recorder[column]++; } // Output empty char in order to solve the problem: // When clearing the screen, the terminal will flicker. for(int curr_processing_row = 0; curr_processing_row < curr_row - this->show_length; curr_processing_row++) { attron(COLOR_PAIR(3)); mvaddch(curr_processing_row, column, ' '); attroff(COLOR_PAIR(3)); } // Upper half of the column should be darker, and the bottom char should be white for(int curr_processing_row = curr_row - this->show_length; curr_processing_row <= curr_row; ++curr_processing_row) { char show_char = character_list[std::rand() % strlen(character_list)]; if(curr_processing_row < 0) { continue; } elseif(curr_processing_row >= this->window_height) { break; } elseif(curr_processing_row == curr_row) { attron(COLOR_PAIR(2)); mvaddch(curr_processing_row, column, show_char); attroff(COLOR_PAIR(2)); } elseif(curr_processing_row < curr_row - this->show_length / 2) { attron(COLOR_PAIR(1)); attron(A_DIM); mvaddch(curr_processing_row, column, show_char); attroff(A_DIM); attron(COLOR_PAIR(1)); } else { attron(COLOR_PAIR(1)); mvaddch(curr_processing_row, column, show_char); attroff(COLOR_PAIR(1)); } }
// Output empty char in order to solve the problem: // When clearing the screen, the terminal will flicker. for(int curr_processing_row = curr_row + 1; curr_processing_row < this->window_height; curr_processing_row++) { attron(COLOR_PAIR(3)); mvaddch(curr_processing_row, column, ' '); attroff(COLOR_PAIR(3)); }