├── .gitignore ├── README.md ├── drawille.hpp └── examples ├── Makefile ├── graph.cpp └── line.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | 30 | # Emacs 31 | \#*# 32 | *~ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | drawille-plusplus 2 | ================= 3 | 4 | An implementation of [drawille](https://github.com/asciimoo/drawille) in C++. 5 | 6 | Do not forget to set your locale with `std::locale::global(std::locale(""));` at the beginning of your program to enable wide-character support. 7 | 8 | Header-only, to use in your project simply include `drawille.hpp` and compile with C++11 support or later. 9 | 10 | I may write more examples at a later date, or you are free to contribute some via pull request. 11 | 12 | Please raise any bugs in the issues section of this repository. 13 | 14 | Special thanks go to [Rei](https://github.com/sovietspaceship) for testing and suggestions. 15 | -------------------------------------------------------------------------------- /drawille.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DRAWILLE_HPP 2 | #define DRAWILLE_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace Drawille { 8 | using std::vector; 9 | using std::wostream; 10 | 11 | constexpr size_t pixmap[4][2] = { 12 | {0x01, 0x08}, 13 | {0x02, 0x10}, 14 | {0x04, 0x20}, 15 | {0x40, 0x80} 16 | }; 17 | 18 | constexpr wchar_t braille = 0x2800; 19 | 20 | class Canvas { 21 | public: 22 | Canvas(size_t width, size_t height) { 23 | this->canvas.resize(height); 24 | for(auto& v: this->canvas) 25 | v.resize(width); 26 | } 27 | 28 | void set(size_t x, size_t y) { 29 | if(x > (this->canvas[0].size() * 2) or x < 1) x = 0; 30 | if(y > (this->canvas.size() * 4) or y < 1) y = 0; 31 | this->canvas[y / 4][x / 2] |= pixmap[y % 4][x % 2]; 32 | } 33 | 34 | void unset(size_t x, size_t y) { 35 | if(x > (this->canvas[0].size() * 2) or x < 1) x = 0; 36 | if(y > (this->canvas.size() * 4) or y < 1) y = 0; 37 | this->canvas[y / 4][x / 2] &= ~pixmap[y % 4][x % 2]; 38 | } 39 | 40 | void draw(wostream& strm) { 41 | for(auto& v: this->canvas) { 42 | for(auto& c: v) { 43 | if(c == 0) strm << " "; 44 | else strm << std::wstring{braille+c}; 45 | } 46 | strm << std::endl; 47 | } 48 | } 49 | 50 | protected: 51 | vector> canvas; 52 | }; 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /examples/Makefile: -------------------------------------------------------------------------------- 1 | CXX?=g++ 2 | CXXFLAGS=-Wall -Werror -pedantic -std=c++14 3 | all: 4 | for f in *.cpp ; do \ 5 | echo "Compiling $$f..."; \ 6 | $(CXX) $$f -o `basename $$f .cpp`".out" $(CXXFLAGS); \ 7 | done; 8 | 9 | clean: 10 | rm *.out 11 | -------------------------------------------------------------------------------- /examples/graph.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "../drawille.hpp" 6 | 7 | using namespace std; 8 | using namespace Drawille; 9 | using std::wcout; 10 | using std::locale; 11 | 12 | //this class contains datasets that you can import and draws a graph using them 13 | class counter{ 14 | public: 15 | int dataset_a; 16 | int dataset_b; 17 | }; 18 | 19 | vector cntrTemp, cntr; 20 | 21 | 22 | void inputDataset(){ 23 | int pos=0; 24 | 25 | /*The data.bin file was made using 26 | 27 | ofstream fout("data.bin", ios::binary|ios::app); 28 | fout.write((char*)&elmnt, sizeof(elmnt)); 29 | 30 | where elmnt is a data memeber of the counter class*/ 31 | 32 | ifstream fin("data.bin", ios::binary); 33 | cntrTemp.emplace_back(counter()); 34 | 35 | while(fin.read((char*)&cntrTemp[pos], sizeof(cntrTemp[pos]))){ 36 | cntrTemp.emplace_back(counter()); 37 | pos = cntrTemp.size()-1; 38 | } 39 | 40 | fin.close(); 41 | 42 | //initializing pos such that only the last 3000 points will be 43 | //entered into cntr 44 | if(cntrTemp.size()<3000) pos=0; 45 | else pos = cntrTemp.size() - 3000; 46 | 47 | //initialising cntr with last 3000 values. i am using 3000 as a limit 48 | //because that is how many will fit on my monitor 49 | for(int i=pos; i 2 | #include 3 | #include "../drawille.hpp" 4 | 5 | using namespace Drawille; 6 | using std::wcout; 7 | using std::locale; 8 | 9 | int main() { 10 | locale::global(locale("")); 11 | Canvas canvas(80, 24); 12 | 13 | for(int i = 0; i <= 10; ++i) { 14 | canvas.set(i, i); 15 | } 16 | 17 | canvas.draw(wcout); 18 | 19 | return 0; 20 | } 21 | --------------------------------------------------------------------------------