Created
January 16, 2019 22:43
-
-
Save towc/7baf459b5cffe05d4cac8df56fdc82c8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <chrono> | |
#include <thread> | |
#include <cstdlib> | |
#include <math.h> | |
#include "render.cpp" | |
#define PI 3.14159265 | |
int main() { | |
int i = 0; | |
render::init(); | |
std::atexit(render::on_exit); | |
while (true) { | |
++i; | |
render::render(static_cast<int>(1500.0 + 300.5 * pow(abs(sin(i / 500.0 * PI)), 5))); | |
std::this_thread::sleep_for(std::chrono::milliseconds(1000/60)); | |
} | |
return 0; | |
} |
This file contains hidden or 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 <vector> | |
namespace render { | |
const int w = 200; | |
const int h = 65; | |
std::string buffer = ""; | |
void write(std::string text) { | |
buffer += text; | |
//std::cout << text << std::flush; | |
} | |
void write(std::vector<std::string> text) { | |
for(const auto& part : text) { | |
//std::cout << part; | |
buffer += part; | |
} | |
//std::cout << std::flush; | |
} | |
void writeln(std::string text) { | |
if (text.length() >= w) { | |
buffer += text.substr(0, w) + "\n"; | |
} else { | |
buffer += text + std::string(w - text.length(), ' ') + "\n"; | |
} | |
} | |
void flush() { | |
std::cout << buffer << std::flush; | |
buffer.clear(); | |
} | |
void pos(int x, int y) { | |
std::string sx = std::to_string(x); | |
std::string sy = std::to_string(y); | |
write({ "\e[", sy, ";", sx, "H" }); | |
} | |
void clear() { | |
//pos(h, 0); | |
//write(std::string(h, '\n')); | |
pos(0, 0); | |
} | |
int max(int a, int b) { | |
return a > b ? a : b; | |
} | |
void render(int i) { | |
clear(); | |
char chars[] = { '.', ':', '+', 'o', 'O', '@'}; | |
int charCount = 6; | |
//write({ "hi ", std::to_string(i), "\n" }); | |
for(int j = i; j > (i - h) && j > 0; --j) { | |
int n = j * 3; | |
int size = max((n/w % 2) == 0 ? n % w : w - (n % w), 3); | |
int offset = abs(j * j&(j+3) + j%i) % 8; | |
const char letter = chars[((j/(charCount-1)) % 2) == 0 ? j % 5 : 5 - (j % 5)]; | |
writeln(std::to_string(j) + " - " + std::string(w/2 - size/2 + offset, ' ') + std::string(size, letter)); | |
} | |
flush(); | |
} | |
void init() { | |
// smcup | |
write("\e[?1049h"); | |
} | |
void on_exit() { | |
// rmcup | |
write("\e[?10491"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment