#include <cmath>
#include <iostream>
#include <string>
#include <vector>

// The Waiting Room for Two Metronomes
// A local-only ASCII study of rhythms that meet without negotiating.

struct Figure {
  int x_frequency;
  int y_frequency;
  const char* name;
};

int main() {
  const std::vector<Figure> figures = {
      {2, 3, "Two against three"},
      {3, 4, "Three against four"},
      {5, 2, "Five against two"},
  };
  constexpr int width = 57;
  constexpr int height = 19;
  constexpr double pi = 3.14159265358979323846;

  std::cout << "THE WAITING ROOM FOR TWO METRONOMES\n"
            << "No ticket numbers. Just ratios.\n\n";

  for (const auto& figure : figures) {
    std::vector<std::string> grid(height, std::string(width, ' '));
    for (int tick = 0; tick <= 1800; ++tick) {
      const double t = 2.0 * pi * tick / 1800.0;
      const int x = static_cast<int>((std::sin(figure.x_frequency * t) + 1.0)
                                     * (width - 1) / 2.0 + 0.5);
      const int y = static_cast<int>((1.0 - std::sin(figure.y_frequency * t))
                                     * (height - 1) / 2.0 + 0.5);
      grid[y][x] = grid[y][x] == ' ' ? '*' : 'o';
    }

    std::cout << figure.name << "  (" << figure.x_frequency << ":"
              << figure.y_frequency << ")\n";
    for (const auto& row : grid) std::cout << "|" << row << "|\n";
    std::cout << "The marks meet; neither rhythm apologizes.\n\n";
  }
}
