#include <iostream> #include <cmath> #include <string> #include <fstream>
using namespace std;
double const PI = 3.14159;
int getCurve(); string getPngFilename(); int getNumPoints(); void getVariableData(int, double&, double&, double&); void circle(int, double); void epicycloid(int, double, double); void hypotrochoid(int, double, double, double); void hypocycloid(int, double, double); void butterfly(int); void writeGnuplotFile(string);
int main () { double Radius, radius, distance;
int selection = getCurve();
string filename = getPngFilename();
int points = getNumPoints();
getVariableData(selection, Radius, radius, distance);
writeGnuplotFile(filename);
if (selection == 1) {
circle(points, Radius);
} else if (selection == 2) {
epicycloid(points, Radius, radius);
} else if (selection == 3) {
hypotrochoid(points, Radius, radius, distance);
} else if (selection == 4) {
hypocycloid(points, Radius, radius);
} else if (selection == 5) {
butterfly(points);
}
output.close;
}
//Prompts for selection; returns an integer int getCurve() { int selection; do { cout << "\nSelect curve to draw." << endl << " 1) Circle" << endl << " 2) Epicycloid" << endl << " 3) Hypotrochoid" << endl << " 4) Hypocycloid" << endl << " 5) Butterfly" << endl << "Choice: "; cin >> selection; if (selection < 1 || selection > 5) { cout << "\nInvalid choice" << endl; } } while (selection < 1 || selection > 5); return selection; }
//Prompts for file name; returns a string string getPngFilename() { cout << "\nType an image name to write to (must end with .png; ex: circle.png)" << endl; string filename; cin >> filename; return filename; }
//Prompts for number of points; returns an integer int getNumPoints() { int points; do { cout << "\nEnter number of points to generate: "; cin >> points; if (points <= 0) { cout << "\nChoose number greater than 0" << endl; } } while (points <= 0); return points; }
//Prompts for correct variables; returns a void void getVariableData(int selection, double& Radius, double& radius, double& distance) { if (selection == 1) { cout << "Enter circle's radius: "; cin >> Radius; } else if (selection == 2) { cout << "Enter epicycloid's stationary circle radius: "; cin >> Radius; cout << "Enter epicycloid's moving circle radius: "; cin >> radius; } else if (selection == 3) { cout << "Enter hypotrochoid's stationary circle radius: "; cin >> Radius; cout << "Enter hypotrochoid's moving circle radius: "; cin >> radius; cout << "Enter drawing point's distance from center of stationary circle: "; cin >> distance; } else if (selection == 4) { cout << "Enter hypocycloid's stationary circle radius: "; cin >> Radius; cout << "Enter hypocycloid's moving circle radius: "; cin >> radius; } else { return; } }
//Idk why this can't be in main or maybe I'm missing something, for the lulz void writeGnuplotFile(string filename) { ofstream output; output.open(filename.c_str()); }
void circle(int points, double Radius) { double theta = 0, x = 1, y = 0; int count = 0;
while (count < points) {
output << x << " " << y << endl;
theta = theta + (2*PI)/180;
x = cos(theta);
y = sin(theta);
count++;
}
}