Update.
[universe.git] / mash.cc
diff --git a/mash.cc b/mash.cc
index ed85d2c..da376b5 100644 (file)
--- a/mash.cc
+++ b/mash.cc
@@ -1,4 +1,3 @@
-// -*- compile-command:"g++ -lX11 -Wall -g -O3 -o mash misc.o universe.o polygon.o mash.cc -L/usr/X11R6/lib/"; -*-
 
 #include <iostream>
 #include <fstream>
@@ -15,7 +14,7 @@ using namespace std;
 #include "universe.h"
 
 int main(int argc, char **argv) {
-  int nb_heur = 75;
+  int nb_heur = 50;
   int w = 1000, h = 1000;
   Universe universe(nb_heur + 1, w, h);
 
@@ -35,7 +34,7 @@ int main(int argc, char **argv) {
       ys[k] = scalar_t(h)/2 + radius * sin(-alpha);
     }
     Polygon *p;
-    p = new Polygon(1.0, 0.5, 0.5, 0.5, xs, ys, nb);
+    p = new Polygon(1.0, 0.0, 0.0, 0.0, xs, ys, nb);
     p->set_position(scalar_t(w/2), scalar_t(h) * 0.75, 0);
     p->set_speed(0, 0, 0);
     universe.initialize(p);
@@ -72,7 +71,7 @@ int main(int argc, char **argv) {
         if(y < 0) y = 0;
         else if(y >= nb_max_edges) y = nb_max_edges-1;
       }
-      fail = (n < 8) || (x != 0) || (y != 0);
+      fail = (n < 10) || (x != 0) || (y != 0);
     } while(fail);
 
     scalar_t xs[nb_max_edges], ys[nb_max_edges];
@@ -80,17 +79,24 @@ int main(int argc, char **argv) {
     for(int l = 0; l < n; l++) {
       int pl = (l + n - 1)%n, nl = (l + 1)%n;
       if(xt[nl] - xt[l] != xt[l] - xt[pl] || yt[nl] - yt[l] != yt[l] - yt[pl]) {
-        xs[nb_edges] = scalar_t(xt[l]) * 15;
-        ys[nb_edges] = scalar_t(yt[l]) * 15;
+        xs[nb_edges] = scalar_t(xt[l]) * 25;
+        ys[nb_edges] = scalar_t(yt[l]) * 25;
         nb_edges++;
       }
     }
 
     cout << "n = " << n << " nb_edges = " << nb_edges << endl;
 
-    blocks[i] = new Polygon(1.0, 1.0, 1.0, 0.0, xs, ys, nb_edges);
+    scalar_t red, green, blue;
     do {
-      blocks[i]->set_position(drand48() * w/2 + w/4, drand48() * h/2 + h/4, M_PI * drand48());
+      red = scalar_t(16 * int(drand48() * 16))/255.0;
+      green = scalar_t(16 * int(drand48() * 16))/255.0;
+      blue = scalar_t(16 * int(drand48() * 16))/255.0;
+    } while((red > 0.1 && green > 0.1 && blue > 0.1) ||
+            (red < 0.9 && green < 0.9 && blue < 0.9));
+    blocks[i] = new Polygon(1.0, red, green, blue, xs, ys, nb_edges);
+    do {
+      blocks[i]->set_position(drand48() * w * 0.9 + w * 0.05, drand48() * 3 * h / 4 + h/8, M_PI * drand48());
       blocks[i]->set_speed(0, 0, 0);
       // universe.initialize(blocks[i]);
       for(int j = 0; j < i + 1; j++) {
@@ -111,14 +117,14 @@ int main(int argc, char **argv) {
     if(n%1000 == 0) {
       char buffer[1024];
       sprintf(buffer, "/tmp/mash_%06d.fig", n);
-      ofstream os(buffer);
-      universe.print_fig(os);
+      XFigTracer tracer(buffer);
+      universe.print_xfig(&tracer);
       cout << "Wrote " << buffer << endl;
     }
   }
 
-  ofstream os("/tmp/mash.fig");
-  universe.print_fig(os);
+  XFigTracer tracer("/tmp/mash.fig");
+  universe.print_xfig(&tracer);
 
   exit(0);
 }