diff --git a/TextScroller/a.out b/TextScroller/a.out new file mode 100755 index 0000000..6116996 Binary files /dev/null and b/TextScroller/a.out differ diff --git a/TextScroller/main.cpp b/TextScroller/main.cpp new file mode 100644 index 0000000..03611f6 --- /dev/null +++ b/TextScroller/main.cpp @@ -0,0 +1,91 @@ +#include +#include +#include // for linux + +using namespace std; + +const string COLOR_ANSI = "\033[38;2;"; +int color[] = {255, 0, 0}; +//bool incDec[] = {false, true, true}; +int currentColor = 1; +int colorIterator = 0; + +std::string updateColor() { + if (colorIterator >= 255) { + currentColor++; + colorIterator = 0; + } + if (currentColor > 2) { + currentColor = 0; + } + switch (currentColor) { + case 0: + if (color[0] < 255) { + color[0]++; + } + if (color[1] > 0) { + color[1]--; + } + if (color[2] > 0) { + color[2]--; + } + break; + case 1: + if (color[0] > 0) { + color[0]--; + } + if (color[1] < 255) { + color[1]++; + } + if (color[2] > 0) { + color[2]--; + } + break; + case 2: + if (color[0] > 0) { + color[0]--; + } + if (color[1] > 0) { + color[1]--; + } + if (color[2] < 255) { + color[2]++; + } + break; + default: + break; + + } + + colorIterator++; + return COLOR_ANSI + std::to_string(color[0]) + ";" + std::to_string(color[1]) + ";" + std::to_string(color[2])+ "m"; +} + + +int main() { + //printf("Hello World!\n"); + std::system("clear"); + string input = "Scrolling text in C++! "; + input += input; + input += input; + input += input; + string colorStr = ""; + for (int i = 0;; ++i) { + //printf("\033[H"); + //colorStr = updateColor(); + //printf ("RGB: %u, %u, %u; colorIterator: %u; currentColor: %u\n", color[0], color[1], color[2], colorIterator, currentColor); + //printf("\n %d ", (i + 1)); + for (int j = 0; j < input.size() - 1; ++j) { + printf("%s%c", updateColor().c_str(), input.at(j)); + //updateColor(); + } + cout << "\n"; + //printf("%s %d %s\n", colorStr.c_str(), (i + 1), input.c_str()); + + input = input.substr((input.size() - 1), input.size()) + input.substr(0, (input.size() - 1)); + usleep(100000); + // Clear screen + //std::system("clear"); + } + return 0; +}