summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2024-10-09 17:00:53 -0400
committerSam Anthony <sam@samanthony.xyz>2024-10-09 17:00:53 -0400
commit20622555ee6eabb3d3c9f618d65b91736dd7097f (patch)
treeabe6faf05b22909c050449084e0c28f7158a6231
parentf48d24f99849fb9e801970bcb124cd49fa2418f6 (diff)
downloadballs-20622555ee6eabb3d3c9f618d65b91736dd7097f.zip
refactor
-rw-r--r--Makefile4
-rw-r--r--balls.cpp26
-rw-r--r--balls.h3
-rw-r--r--point.cpp5
-rw-r--r--rand.cpp31
5 files changed, 35 insertions, 34 deletions
diff --git a/Makefile b/Makefile
index 94a8553..1704814 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ CC = g++
CFLAGS = -Wall -pedantic
LDFLAGS = -ltbb -lglut -lGLU -lGL
-balls: balls.o collision.o point.o vec.o partition.o
+balls: balls.o collision.o point.o vec.o partition.o rand.o
${CC} -o $@ $^ ${LDFLAGS}
@echo done
@@ -10,4 +10,4 @@ balls: balls.o collision.o point.o vec.o partition.o
${CC} -c ${CFLAGS} $<
clean:
- rm -f ./*.o balls \ No newline at end of file
+ rm -f ./*.o balls
diff --git a/balls.cpp b/balls.cpp
index 2c8172f..b3f245d 100644
--- a/balls.cpp
+++ b/balls.cpp
@@ -35,7 +35,6 @@ vector<Point> noOverlapCircles(unsigned int n);
double mass(double radius);
double volume(double radius);
void animate(int v);
-Color randColor(void);
const static Rectangle bounds = {{-1.5, -1.0}, {1.5, 1.0}};
@@ -217,28 +216,3 @@ animate(int v) {
display();
glutTimerFunc(FRAME_TIME_MS, animate, 0);
}
-
-double
-randDouble(double lo, double hi) {
- double r, diff;
- static int isInitialized = 0;
-
- if (!isInitialized) { /* first call */
- srand(time(0));
- isInitialized = 1;
- }
-
- r = (double) rand() / (double) RAND_MAX;
- diff = hi - lo;
- return lo + r*diff;
-}
-
-Color
-randColor(void) {
- Color color;
-
- color.r = randDouble(0, 1);
- color.g = randDouble(0, 1);
- color.b = randDouble(0, 1);
- return color;
-}
diff --git a/balls.h b/balls.h
index 27bffde..4d070c9 100644
--- a/balls.h
+++ b/balls.h
@@ -63,7 +63,6 @@ Point ptMulS(Point p, double s);
Point ptDivS(Point p, double s);
Point Pt(double x, double y);
Rectangle insetRect(Rectangle r, double n);
-Point randPtInRect(Rectangle r);
Vector addVec(Vector v1, Vector v2);
Vector subVec(Vector v1, Vector v2);
@@ -80,3 +79,5 @@ void collideWall(Ball *b, Rectangle wall);
void collideBall(Ball *b1, Ball *b2);
double randDouble(double lo, double hi);
+Color randColor(void);
+Point randPtInRect(Rectangle r);
diff --git a/point.cpp b/point.cpp
index 099165d..7d73b31 100644
--- a/point.cpp
+++ b/point.cpp
@@ -56,8 +56,3 @@ insetRect(Rectangle r, double n) {
r.max.y -= n;
return r;
}
-
-Point
-randPtInRect(Rectangle r) {
- return Pt(randDouble(r.min.x, r.max.x), randDouble(r.min.y, r.max.y));
-}
diff --git a/rand.cpp b/rand.cpp
new file mode 100644
index 0000000..7a327ee
--- /dev/null
+++ b/rand.cpp
@@ -0,0 +1,31 @@
+#include "balls.h"
+
+double
+randDouble(double lo, double hi) {
+ double r, diff;
+ static int isInitialized = 0;
+
+ if (!isInitialized) { /* first call */
+ srand(time(0));
+ isInitialized = 1;
+ }
+
+ r = (double) rand() / (double) RAND_MAX;
+ diff = hi - lo;
+ return lo + r*diff;
+}
+
+Color
+randColor(void) {
+ Color color;
+
+ color.r = randDouble(0, 1);
+ color.g = randDouble(0, 1);
+ color.b = randDouble(0, 1);
+ return color;
+}
+
+Point
+randPtInRect(Rectangle r) {
+ return Pt(randDouble(r.min.x, r.max.x), randDouble(r.min.y, r.max.y));
+}