fill.cpp 951 B

1234567891011121314151617181920212223242526272829303132333435
  1. #define _USE_MATH_DEFINES
  2. #include "../matplotlibcpp.h"
  3. #include <cmath>
  4. using namespace std;
  5. namespace plt = matplotlibcpp;
  6. // Example fill plot taken from:
  7. // https://matplotlib.org/gallery/misc/fill_spiral.html
  8. int main() {
  9. // Prepare data.
  10. vector<double> theta;
  11. for (double d = 0; d < 8 * M_PI; d += 0.1)
  12. theta.push_back(d);
  13. const int a = 1;
  14. const double b = 0.2;
  15. for (double dt = 0; dt < 2 * M_PI; dt += M_PI/2.0) {
  16. vector<double> x1, y1, x2, y2;
  17. for (double th : theta) {
  18. x1.push_back( a*cos(th + dt) * exp(b*th) );
  19. y1.push_back( a*sin(th + dt) * exp(b*th) );
  20. x2.push_back( a*cos(th + dt + M_PI/4.0) * exp(b*th) );
  21. y2.push_back( a*sin(th + dt + M_PI/4.0) * exp(b*th) );
  22. }
  23. x1.insert(x1.end(), x2.rbegin(), x2.rend());
  24. y1.insert(y1.end(), y2.rbegin(), y2.rend());
  25. plt::fill(x1, y1, {});
  26. }
  27. plt::show();
  28. }