#pragma once #include "vec.hpp" #include #include #include #include #include #include #include struct Screen { /** * Unit pixel information struct */ struct Symbol { char sym; vec<3> color = {0,0,0}; bool visible = true; Symbol &operator=(char c) { sym = c; return *this; }; }; /** * Function taking screen coords and space coords and returning a Symbol for * that position */ using char_shader_t = std::function; std::size_t w, h; float dx = 0, dy = 0; float sx = 1, sy = 1.8; void draw(); void clear(); Symbol &at(std::size_t n); Symbol &at(int x, int y); Symbol &at(float x, float y); void resize(std::size_t n); void resize(std::size_t x, std::size_t y); std::pair screen_to_xy(int w, int h); std::pair xy_to_screen(float x, float y); Screen(std::size_t n) : buf(nullptr) { resize(n); } Screen(std::size_t x, std::size_t y) : buf(nullptr) { resize(x, y); } ~Screen() { delete[] buf; } std::vector*> points; char_shader_t shader; private: Symbol *buf; Symbol _dummy; static inline void gotoxy(int x, int y) { std::printf("\033[%d;%dH", y, x); } }; using colorizer_t = std::function(float)>; struct TanhColorizer { float scale = 1.0; float translate = 0.0; vec<3> operator()(float y); private: static vec<3> hsl_to_rgb(float h, float s, float l); static float hue_to_rgb(float p, float q, float t); }; static termios old, current; static inline void enter_noncanonical_mode(void) { tcgetattr(STDIN_FILENO, &old); current = old; current.c_lflag &= ~ICANON; /* disable buffered i/o */ current.c_lflag &= ~ECHO; /* set no echo mode */ current.c_cc[VMIN] = 0;/* no wait */ current.c_cc[VTIME] = 0;/* no wait */ tcsetattr(STDIN_FILENO, TCSANOW, ¤t); } static inline void enter_canonical_mode(void){ tcsetattr(0, TCSANOW, &old); }