|
#include <ncurses.h>
#include <stdlib.h>
#include <time.h>
#define NUM_BARS 64
#define MAX_HEIGHT 20
void drawBars(int *heights) {
clear();
for (int i = 0; i < NUM_BARS; ++i) {
for (int j = 0; j < heights[i]; ++j) {
mvprintw(LINES - j - 1, i * 2, "||");
}
}
refresh();
}
void updateHeights(int *heights) {
for (int i = 0; i < NUM_BARS; ++i) {
heights[i] = rand() % (MAX_HEIGHT + 1);
}
}
int main() {
srand(time(NULL));
initscr();
noecho();
curs_set(FALSE);
timeout(100); // Non-blocking input with timeout
int heights[NUM_BARS] = {0};
int quit = 0;
while (!quit) {
int ch = getch();
if (ch == 'q' || ch == 'Q') {
quit = 1;
}
updateHeights(heights);
drawBars(heights);
}
endwin();
return 0;
}
问chatgpt的 |
|