diff options
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | balls.cpp | 26 | ||||
| -rw-r--r-- | balls.h | 3 | ||||
| -rw-r--r-- | point.cpp | 5 | ||||
| -rw-r--r-- | rand.cpp | 31 |
5 files changed, 35 insertions, 34 deletions
@@ -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 @@ -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; -} @@ -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); @@ -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)); +} |