Skip to content

Scale The Canvas? #435

Answered by ArthurSonzogni
Kailokk asked this question in Q&A
Jul 7, 2022 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hello,
Thanks for using FTXUI!

I haven't tested it, but from my mind, I would have tried to scale it manually:

V1 (basic)

ftxui::Component Oscilloscope(float**& bufferPointer) {
  return Renderer([&] {
    auto my_Canvas = canvas([&](Canvas& c) {
      if (c.width() == 0)
        return;
      auto sample_y = [&](int x_not_scaled) {
        float x = x_not_scalled * FRAMES_PER_BUFFER / c.width();
        return (*bufferPointer)[std::floor(x)];
      };
      int y = sampled_y(0) * 20;
      for (int x = 0; x < c.width() - 1; x++) {
        float y_next = sample_y(x) * 20;
        c.DrawPointLine(x - 1, y, x, y_next);
        y = y_next;
      }
    });
    return my_Canvas | flex;
  });
}

V…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Kailokk
Comment options

Answer selected by Kailokk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants