Created
December 21, 2019 12:43
-
-
Save jniemann66/af1e29dd7ea93856e66d1a60f826dc5a 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
#ifndef UGLYPLOT_H | |
#define UGLYPLOT_H | |
#include <iostream> | |
#include <cmath> | |
class UglyPlot | |
{ | |
public: | |
static void plot(const double* p, int length) | |
{ | |
constexpr int cols = 80; | |
constexpr int center = cols / 2; | |
double peak = 0.0; | |
for(int n = 0; n < length; n++) { | |
peak = std::max(std::abs(p[n]), peak); | |
} | |
double scale = center / peak; | |
for(int r = 0; r < length; r++) { | |
int a = std::round(center + scale * p[r]); | |
int b = cols - a; | |
std::string s(a, ' '); | |
std::string t(b, ' '); | |
std::cout << s << "*" << t << p[r] << "\n"; | |
} | |
std::cout << std::endl; | |
} | |
}; | |
#endif // UGLYPLOT_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment