mirror of
https://github.com/Kaehvaman/OAIP.git
synced 2025-01-18 16:49:11 +04:00
print colors
This commit is contained in:
parent
71a946ecf0
commit
97a44aae9a
53
clock/main.c
53
clock/main.c
@ -12,7 +12,7 @@ void wait(int seconds) {
|
|||||||
clock_t t0 = clock();
|
clock_t t0 = clock();
|
||||||
clock_t t1;
|
clock_t t1;
|
||||||
while ((int)(((t1 = clock()) - t0) / CLOCKS_PER_SEC) < seconds) {
|
while ((int)(((t1 = clock()) - t0) / CLOCKS_PER_SEC) < seconds) {
|
||||||
Sleep(50);
|
Sleep(1000);
|
||||||
}
|
}
|
||||||
printf(" wait for %d s is over, clock=%d", seconds, (int)t1);
|
printf(" wait for %d s is over, clock=%d", seconds, (int)t1);
|
||||||
}
|
}
|
||||||
@ -24,27 +24,64 @@ int main() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct progressbar pb;
|
struct progressbar pb;
|
||||||
int n = 5, sl = 1;
|
int n = 10, sl = 1;
|
||||||
printf(HIDE_CURSOR);
|
printf(HIDE_CURSOR);
|
||||||
|
printf("\033[385;31m");
|
||||||
progressbar_start(&pb, n * sl);
|
progressbar_start(&pb, n * sl);
|
||||||
|
|
||||||
clock_t start = clock();
|
clock_t start = clock();
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 1; i <= n; i++) {
|
||||||
|
int percentage = 100 * i / n;
|
||||||
|
if (percentage < 33) {
|
||||||
|
printf("\033[385;31m");
|
||||||
|
}
|
||||||
|
else if (33 < percentage && percentage < 66) {
|
||||||
|
printf("\033[385;33m");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("\033[385;32m");
|
||||||
|
}
|
||||||
wait(sl);
|
wait(sl);
|
||||||
//printf("%d\n", i);
|
//printf("%d\n", i);
|
||||||
progressbar_add(&pb, sl);
|
progressbar_add(&pb, sl);
|
||||||
}
|
}
|
||||||
//progressbar_clear();
|
//progressbar_clear();
|
||||||
|
printf("\033[0m");
|
||||||
printf(SHOW_CURSOR);
|
printf(SHOW_CURSOR);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf_s("time = %.3lf seconds\nexpected %d seconds\n", (double)(clock() - start) / (double)CLOCKS_PER_SEC, n * sl);
|
printf_s("time = %.3lf seconds\nexpected %d seconds\n", (double)(clock() - start) / (double)CLOCKS_PER_SEC, n * sl);
|
||||||
|
|
||||||
progressbar_start(&pb, n * sl);
|
int count = 0;
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 40; i <= 47; i++) {
|
||||||
wait(sl);
|
printf("\033[385;%dm", i);
|
||||||
//printf("%d\n", i);
|
for (int j = 30; j <= 37; j++) {
|
||||||
progressbar_add(&pb, sl);
|
printf("\033[385;%dm", j);
|
||||||
|
printf("%2X ", count);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
for (int j = 90; j <= 97; j++) {
|
||||||
|
printf("\033[385;%dm", j);
|
||||||
|
printf("%2X ", count);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
for (int i = 100; i <= 107; i++) {
|
||||||
|
printf("\033[385;%dm", i);
|
||||||
|
for (int j = 30; j <= 37; j++) {
|
||||||
|
printf("\033[385;%dm", j);
|
||||||
|
printf("%2X ", count);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
for (int j = 90; j <= 97; j++) {
|
||||||
|
printf("\033[385;%dm", j);
|
||||||
|
printf("%2X ", count);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
printf("\033[0m");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -9,7 +9,7 @@ static unsigned get_to_print(unsigned current, unsigned max) {
|
|||||||
return progressbar_width * current / max;
|
return progressbar_width * current / max;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned get_percentage(unsigned current, unsigned max) {
|
unsigned get_percentage(unsigned current, unsigned max) {
|
||||||
return 100 * current / max;
|
return 100 * current / max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,4 +17,6 @@ void progressbar_inc(struct progressbar *pb);
|
|||||||
// clear line of progress bar
|
// clear line of progress bar
|
||||||
void progressbar_clear();
|
void progressbar_clear();
|
||||||
|
|
||||||
|
unsigned get_percentage(unsigned current, unsigned max);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user