#include <chrono>
#include <cmath>
#include <functional>
#include <iostream>
#include <memory>
#include <string>
#include <thread>
#include <vector>
class Graph {
public:
std::vector<int> operator()(int width, int height) const {
std::vector<int> output(width);
for (int i = 0; i < width; ++i) {
float v = 0;
v += 0.1f * sin((i + shift) * 0.1f);
v += 0.2f * sin((i + shift + 10) * 0.15f);
v += 0.1f * sin((i + shift) * 0.03f);
v *= height;
v += 0.5f * height;
output[i] = static_cast<int>(v);
}
return output;
}
int shift = 0;
};
std::vector<int> triangle(int width, int height) {
std::vector<int> output(width);
for (int i = 0; i < width; ++i) {
output[i] = i % (height - 4) + 2;
}
return output;
}
int main() {
using namespace std::chrono_literals;
Graph my_graph;
std::string reset_position;
for (int i = 0;; ++i) {
graph(std::ref(my_graph)),
});
const int min_width = 40;
std::cout << reset_position;
screen.Print();
reset_position = screen.ResetPosition();
const auto sleep_time = 0.03s;
std::this_thread::sleep_for(sleep_time);
my_graph.shift++;
}
return 0;
}
static Screen Create(Dimensions dimension)
Create a screen with the given dimension.
Dimensions Fit(Element &, bool extend_beyond_screen=false)
Decorator size(WidthOrHeight, Constraint, int value)
Apply a constraint on the size of an element.
Element flex(Element)
Make a child element to expand proportionally to the space left in a container.
Element hbox(Elements)
A container displaying elements horizontally one by one.
Element inverted(Element)
Add a filter that will invert the foreground and the background colors.
Element separator()
Draw a vertical or horizontal separation in between two other elements.
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
Element graph(GraphFunction)
Draw a graph using a GraphFunction.
Element border(Element)
Draw a border around the element.
Decorator color(Color)
Decorate using a foreground color.
Element vbox(Elements)
A container displaying elements vertically one by one.