C#include <windows.h>
#include <iostream>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
#include<bits/stdc++.h>
#include <iostream>
#include "conio.h"
using namespace std;
POINT p;
HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
HWND h=GetForegroundWindow();
CONSOLE_FONT_INFO consoleCurrentFont;
void S(int x, int y) {
COORD pos = {y,x};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut, pos);
}
void HideTheCursor() {
CONSOLE_CURSOR_INFO cciCursor;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {
cciCursor.bVisible = FALSE;
SetConsoleCursorInfo(hStdOut, &cciCursor);
}
}
void C(int wr,int wg,int wb,int br,int bg,int bb) {
printf("\033[38;2;%d;%d;%dm\033[48;2;%d;%d;%dm",wr,wg,wb,br,bg,bb);
}
struct f{
int x,y;
};
queue<f>Q;
f g;
int s=0;
int R=213,G=98,B=87;
bool b,b2,b3;
int hh=35;
int main() {
HideTheCursor();
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
GetConsoleMode(hStdin, &mode);
mode &= ~ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(hStdin, mode);
HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD dwInMode, dwOutMode;
GetConsoleMode(hIn, &dwInMode);
GetConsoleMode(hOut, &dwOutMode);
dwInMode |= 0x0200;
dwOutMode |= 0x0004;
SetConsoleMode(hIn, dwInMode);
SetConsoleMode(hOut, dwOutMode);
cout<<"输入初始的R.G.B码:";
cin>>R>>G>>B;
S(0,0);
C(0,0,0,0,0,0);
for(int i=0;i<10000;i++){
cout<<" ";
}
S(0,0);
cout<<"空格键可暂停,下滑有颜色的R.G.B,再按一次空格可复原……";
Sleep(1000);
system("cls");
bool bb=1;
char con='@';
while(1) {
if(_kbhit()){
con=getch();
}
else con='@';
if(con==' '){
bb=!bb;
}
else con=' ';
if(bb){
POINT p;
GetCursorPos(&p);
ScreenToClient(h,&p);
GetCurrentConsoleFont(hOutput, FALSE, &consoleCurrentFont);
int y=p.x/=consoleCurrentFont.dwFontSize.X;
int x=p.y/=consoleCurrentFont.dwFontSize.Y;
S(x,y);
if(R>255){
b=0;
R=255;
}
if(G>255){
b2=0;
G=255;
}
if(B>255){
b3=0;
b=255;
}
if(R<=0)b=1;
if(G<=0)b2=1;
if(B<=0)b3=1;
C(R,G,B,R,G,B);
if(b)R++;else R--;
if(b2)G++;else G--;
if(b3)B++;else B--;
cout<<" ";
Q.push({x,y});
s++;
C(0,0,0,255,255,255);
S(30,0);
if(s>10){
if(Q.size()){
g=Q.front();
Q.pop();
S(g.x,g.y);
C(255,255,255,0,0,0);cout<<" ";
s=10;
}
}
S(hh,0);
C(255,255,255,R,G,B);
cout<<R<<" "<<G<<" "<<B;
hh++;
S(0,0);
Sleep(10);
}
}
return 0;
}