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