summaryrefslogtreecommitdiffstats
path: root/balls.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'balls.cpp')
-rw-r--r--balls.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/balls.cpp b/balls.cpp
index 0f870ff..e7a5a28 100644
--- a/balls.cpp
+++ b/balls.cpp
@@ -31,13 +31,13 @@ enum {
void keyboard(unsigned char key, int x, int y);
void display(void);
-void drawBg(void);
+void drawBackground(void);
void drawCircle(double radius, Point p);
void reshape(int w, int h);
vector<Ball> makeBalls(unsigned int n);
vector<Point> noOverlapCircles(unsigned int n);
double mass(double radius);
-double volumeSphere(double radius);
+double volume(double radius);
void animate(int v);
const static Rectangle bounds = {{-1.5, -1.0}, {1.5, 1.0}};
@@ -74,7 +74,7 @@ void
display(void) {
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
- drawBg();
+ drawBackground();
for (Ball b : balls)
drawCircle(b.r, b.p);
@@ -82,7 +82,7 @@ display(void) {
}
void
-drawBg(void) {
+drawBackground(void) {
glColor3f(1, 1, 1);
glBegin(GL_QUADS);
glVertex2f(bounds.min.x, bounds.min.y);
@@ -124,6 +124,7 @@ reshape(int w, int h) {
glMatrixMode(GL_MODELVIEW);
}
+/* return n-length vector of Balls with random attributes */
vector<Ball>
makeBalls(unsigned int n) {
vector<Ball> balls(n);
@@ -145,6 +146,7 @@ makeBalls(unsigned int n) {
return balls;
}
+/* return n-length vector of positions of non-overlapping circles with radius RMAX within the bounds */
vector<Point>
noOverlapCircles(unsigned int n) {
vector<Point> ps(n);
@@ -170,12 +172,12 @@ noOverlapCircles(unsigned int n) {
/* mass [kg] of ball as function of radius [m] */
double
mass(double radius) {
- return volumeSphere(radius) * DENSITY;
+ return volume(radius) * DENSITY;
}
-/* volume [m^3] of sphere as function of radius [m] */
+/* volume [m^3] of ball as function of radius [m] */
double
-volumeSphere(double radius) {
+volume(double radius) {
return 4.0 * M_PI * radius*radius*radius / 3.0;
}