Created
June 23, 2014 04:26
-
-
Save zhongwencool/f396eea44a515da96806 to your computer and use it in GitHub Desktop.
Hacker rain compile by g++ -std=c++0x hackerRain.cpp
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
#pragma once | |
#include <iostream> | |
#include <windows.h> | |
inline std::ostream& blue(std::ostream &s) | |
{ | |
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE); | |
SetConsoleTextAttribute(hStdout, FOREGROUND_BLUE | |
|FOREGROUND_GREEN|FOREGROUND_INTENSITY); | |
return s; | |
} | |
inline std::ostream& red(std::ostream &s) | |
{ | |
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE); | |
SetConsoleTextAttribute(hStdout, | |
FOREGROUND_RED|FOREGROUND_INTENSITY); | |
return s; | |
} | |
inline std::ostream& green(std::ostream &s) | |
{ | |
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE); | |
SetConsoleTextAttribute(hStdout, | |
FOREGROUND_GREEN|FOREGROUND_INTENSITY); | |
return s; | |
} | |
inline std::ostream& yellow(std::ostream &s) | |
{ | |
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE); | |
SetConsoleTextAttribute(hStdout, | |
FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY); | |
return s; | |
} | |
inline std::ostream& white(std::ostream &s) | |
{ | |
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE); | |
SetConsoleTextAttribute(hStdout, | |
FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE); | |
return s; | |
} | |
struct color { | |
color(WORD attribute):m_color(attribute){}; | |
WORD m_color; | |
}; | |
template <class _Elem, class _Traits> | |
std::basic_ostream<_Elem,_Traits>& | |
operator<<(std::basic_ostream<_Elem,_Traits>& i, color& c) | |
{ | |
HANDLE hStdout=GetStdHandle(STD_OUTPUT_HANDLE); | |
SetConsoleTextAttribute(hStdout,c.m_color); | |
return i; | |
} | |
// Copyleft Vincent Godin |
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 <string> | |
#include <chrono> | |
#include <thread> | |
#include <cstdlib> | |
#include "console_color.h" | |
const int width = 158; | |
const int flipsPerLine = 5; | |
const int millisecondsOfSleep = 50; | |
int main() { | |
srand(time_t(NULL)); | |
bool switches[width] = { true }; | |
const std::string garbage = "1234567890/*-+.,./;[]\\=_~`!@#$%^&*()"; | |
const auto glen = garbage.size(); | |
while (true) { // Waiting for Ctrl-C | |
for (int i = 0; i != width; ++i) { | |
if (switches[i]) { | |
std::cout << green << garbage[rand() % glen]; | |
} else { | |
std::cout << ' '; | |
} | |
} | |
std::cout << std::endl; | |
for (int i = 0; i != flipsPerLine; ++i) { | |
int x = rand() % width; | |
switches[x] = !switches[x]; | |
} | |
std::this_thread::sleep_for(std::chrono::milliseconds(millisecondsOfSleep)); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can find Data flow like waterfall,very cool..........................
![hacker Rain](https://camo.githubusercontent.com/a0cca6d7372ca970ffdd55a0440bbc5f59443efc18cae16501cf8cfb5572d8a2/687474703a2f2f7a686f6e6777656e636f6f6c2e71696e6975646e2e636f6d2f6861636b65725f7261696e2e706e67)