Created
April 1, 2016 17:45
-
-
Save piotrbla/5916793483f79b421b1f22f34adfa202 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 <iostream> | |
#include <windows.h> | |
#include <stdio.h> | |
void printColors(HANDLE hWnd) | |
{ | |
for (auto i = 0; i < 16; i++) | |
{ | |
for (auto j = 0; j < 16; j++) | |
{ | |
SetConsoleTextAttribute(hWnd, (i+j)%16); | |
printf("%c%2d::", 'A' + j, i); | |
} | |
printf("\n"); | |
} | |
} | |
void setPallete(HANDLE hWnd, int baseColor) | |
{ | |
CONSOLE_SCREEN_BUFFER_INFOEX buffer; | |
buffer.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX); | |
GetConsoleScreenBufferInfoEx(hWnd, &buffer); | |
for (auto i = 0; i < 16; i++) | |
buffer.ColorTable[i] = baseColor + baseColor * i; | |
buffer.srWindow.Right += 1;//http://gynvael.coldwind.pl/?id=594 | |
buffer.srWindow.Bottom += 1; | |
SetConsoleScreenBufferInfoEx(hWnd, &buffer); | |
} | |
void shiftPallette(HANDLE hWnd) | |
{ | |
CONSOLE_SCREEN_BUFFER_INFOEX buffer; | |
buffer.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX); | |
GetConsoleScreenBufferInfoEx(hWnd, &buffer); | |
auto colorToshift = buffer.ColorTable[0]; | |
for (auto i = 0; i < 15; i++) | |
buffer.ColorTable[i] = buffer.ColorTable[i+1]; | |
buffer.ColorTable[15] = colorToshift; | |
buffer.srWindow.Right = 80;//http://gynvael.coldwind.pl/?id=594 | |
buffer.srWindow.Bottom = 44; | |
SetConsoleScreenBufferInfoEx(hWnd, &buffer); | |
} | |
int main() | |
{ | |
auto hWnd = GetStdHandle(STD_OUTPUT_HANDLE); | |
auto const RED_CONSOLE_COLOR = 0x00000010; | |
setPallete(hWnd, RED_CONSOLE_COLOR); | |
printColors(hWnd); | |
auto const GREEN_CONSOLE_COLOR = 0x00001000; | |
setPallete(hWnd, GREEN_CONSOLE_COLOR); | |
printColors(hWnd); | |
auto const BLUE_CONSOLE_COLOR = 0x00100000; | |
setPallete(hWnd, BLUE_CONSOLE_COLOR); | |
printColors(hWnd); | |
for (auto i = 0; i < 100; i++) | |
{ | |
shiftPallette(hWnd); | |
Sleep(100); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment