-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
91 lines (72 loc) · 2.57 KB
/
Copy pathmain.cpp
File metadata and controls
91 lines (72 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include <fstream>
#include "Cylinder.cpp"
double getHeightFromUserInput();
double getRadiusFromUserInput();
int getResolutionFromUserInput();
void PrintCheekyCommentOnResolution(int resolution);
void renderCylinderToOutfile(double height, double radius, int resolution);
void printMessage(std::string message) {
std::cout << message << std::endl;
}
int main() {
std::cout << "A command-line-program to render a cylinder to stl" << std::endl;
double height = getHeightFromUserInput();
double radius = getRadiusFromUserInput();
int resolution = getResolutionFromUserInput();
PrintCheekyCommentOnResolution(resolution);
renderCylinderToOutfile(height, radius, resolution);
printMessage("\n\nRendered cylinder to cylinder.stl next to the executable.");
return 0;
}
void renderCylinderToOutfile(double height, double radius, int resolution) {
Cylinder cylinder = Cylinder(height, radius);
std::string renderedScene = cylinder.render(resolution);
std::ofstream outfile;
outfile.open("cylinder.stl");
outfile << renderedScene;
outfile.close();
}
void PrintCheekyCommentOnResolution(int resolution) {
if (resolution < 7) {
std::cout << "Edgy!" << std::endl;
} else if (resolution < 20) {
std::cout << "Here you go!" << std::endl;
} else if (resolution < 100) {
std::cout << "Mmh, so smooth" << std::endl;
} else if (resolution < 5000) {
std::cout << "You must have an amazing printer!" << std::endl;
} else if (resolution < 50000) {
std::cout << "Yea, I can still do that" << std::endl;
} else if (resolution < 500000) {
std::cout << "Ok, give me a sec" << std::endl;
} else if (resolution < 1000000) {
printMessage("Are you trying to heat your room with a CPU?");
} else if (resolution >= 1000000) {
printMessage("This is a benchmark, right?");
}
}
int getResolutionFromUserInput() {
int resolution;
do {
std::cout << "Enter the desired NUMBER OF SIDES of the cylinder when rendered (>= 3)" << std::endl;
std::cin >> resolution;
} while (resolution < 3);
return resolution;
}
double getHeightFromUserInput() {
double height = 0;
do {
std::cout << "Enter the HEIGHT of the cylinder (>0)" << std::endl;
std::cin >> height;
} while (!(height > 0));
return height;
}
double getRadiusFromUserInput() {
double radius;
do {
std::cout << "Enter the RADIUS of the cylinder (>0)" << std::endl;
std::cin >> radius;
} while (!(radius>0));
return radius;
}