Skip to content

Instantly share code, notes, and snippets.

@vocalinternet
Created October 8, 2022 17:01
Show Gist options
  • Save vocalinternet/ae8e39a7dbcf3c79ee784539063a1c1a to your computer and use it in GitHub Desktop.
Save vocalinternet/ae8e39a7dbcf3c79ee784539063a1c1a to your computer and use it in GitHub Desktop.
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
int main()
{
int size = 80, height = 21;
// Start with an empty chart (lots of spaces and a line in the middle)
std::vector<std::string> chart(height, std::string(size, ' '));
chart[height/2] = std::string(size, '-');
// Then just put x-es where the function should be plotted
for(int i = 0; i < size; i++) {
chart[static_cast<int>(std::round(10 * std::sin(i / 4.5) + 10))][i] = '*';
}
// and print the whole shebang
for(auto &&s : chart) {
std::cout << s << '\n';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment