Created
June 12, 2019 09:59
-
-
Save hyrious/d8d9e3dfc7a0f4891bbe7e4f64eef0da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <time.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <windows.h> | |
void cls( HANDLE hConsole ) { | |
COORD coordScreen = { 0, 0 }; | |
DWORD cCharsWritten; | |
CONSOLE_SCREEN_BUFFER_INFO csbi; | |
DWORD dwConSize; | |
if( !GetConsoleScreenBufferInfo( hConsole, &csbi )) return; | |
dwConSize = csbi.dwSize.X * csbi.dwSize.Y; | |
if( !FillConsoleOutputCharacter( hConsole, // Handle to console screen buffer | |
(TCHAR) ' ', // Character to write to the buffer | |
dwConSize, // Number of cells to write | |
coordScreen, // Coordinates of first cell | |
&cCharsWritten ))// Receive number of characters written | |
{ | |
return; | |
} | |
if( !GetConsoleScreenBufferInfo( hConsole, &csbi )) return; | |
if( !FillConsoleOutputAttribute( hConsole, // Handle to console screen buffer | |
csbi.wAttributes, // Character attributes to use | |
dwConSize, // Number of cells to set attribute | |
coordScreen, // Coordinates of first cell | |
&cCharsWritten )) // Receive number of characters written | |
{ | |
return; | |
} | |
SetConsoleCursorPosition( hConsole, coordScreen ); | |
} | |
int main(void) { | |
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); | |
while (1) { | |
Sleep(1000); | |
cls(h); | |
time_t t = time(0); | |
for (int i = 0; i < 20; ++i) { | |
time_t s = t + i; | |
struct tm* p = localtime(&s); | |
char info[256]; | |
strftime(info, 256, "%H:%M:%S", p); | |
srand(s); | |
printf("%s: ", info); | |
int c = 0; | |
for (int j = 0; j < 10; ++j) { | |
double v = rand() * 1.0 / RAND_MAX; | |
if (v < 0.05) { | |
SetConsoleTextAttribute(h, FOREGROUND_GREEN | FOREGROUND_INTENSITY); | |
} else { | |
SetConsoleTextAttribute(h, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); | |
} | |
printf("%.2lf ", v); | |
if (v < 0.02) c++; | |
} | |
if (c == 1) { | |
SetConsoleTextAttribute(h, FOREGROUND_GREEN); | |
} else if (c > 1) { | |
SetConsoleTextAttribute(h, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | BACKGROUND_GREEN | FOREGROUND_INTENSITY); | |
} else { | |
SetConsoleTextAttribute(h, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); | |
} | |
printf("= %d\n", c); | |
SetConsoleTextAttribute(h, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); | |
} | |
fflush(stdout); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment