#include "universe.h"
int main(int argc, char **argv) {
- int nb_heur = 100;
+ int nb_heur = 75;
int w = 1000, h = 1000;
Universe universe(nb_heur + 1, w, h);
universe.add_polygon(p);
}
- scalar_t xs[] = { -30, 30, 30, -30 };
- scalar_t ys[] = { -10, -10, 10, 10 };
-
Polygon *blocks[nb_heur];
- for(int h = 0; h < nb_heur; h++) {
- blocks[h] = new Polygon(1.0, 1.0, 1.0, 0.0, xs, ys, 4);
+ for(int i = 0; i < nb_heur; i++) {
+
+ int nb_max_edges = 10;
+ int xt[nb_max_edges * nb_max_edges], yt[nb_max_edges * nb_max_edges];
+ int used[nb_max_edges * nb_max_edges];
+ int fail, x, y, n;
do {
- blocks[h]->set_position(drand48() * w, drand48() * h/10, M_PI * drand48());
- blocks[h]->set_speed(0, 0, 0);
- } while(universe.collide(blocks[h]));
- universe.initialize(blocks[h]);
- universe.add_polygon(blocks[h]);
+ fail = 0;
+ for(int k = 0; k < nb_max_edges * nb_max_edges; k++) {
+ used[k] = 0;
+ }
+ x = 0; y = 0; n = 0;
+ while(!used[x + nb_max_edges * y]) {
+ used[x + nb_max_edges * y] = 1;
+ xt[n] = x; yt[n] = y;
+ n++;
+ switch(int(drand48() * 4)) {
+ case 0: x++; break;
+ case 1: x--; break;
+ case 2: y++; break;
+ case 3: y--; break;
+ default: abort();
+ }
+ if(x < 0) x = 0;
+ else if(x >= nb_max_edges) x = nb_max_edges-1;
+ if(y < 0) y = 0;
+ else if(y >= nb_max_edges) y = nb_max_edges-1;
+ }
+ fail = (n < 8) || (x != 0) || (y != 0);
+ } while(fail);
+
+ scalar_t xs[nb_max_edges], ys[nb_max_edges];
+ int nb_edges = 0;
+ 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;
+ 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);
+ do {
+ blocks[i]->set_position(drand48() * w/2 + w/4, drand48() * h/2 + h/4, M_PI * drand48());
+ blocks[i]->set_speed(0, 0, 0);
+ // universe.initialize(blocks[i]);
+ for(int j = 0; j < i + 1; j++) {
+ universe.initialize(blocks[j]);
+ }
+ } while(universe.collide(blocks[i]));
+ universe.add_polygon(blocks[i]);
+ cout << "added " << i+1 << " blocks." << endl;
}
- scalar_t dt = 0.01;
+ scalar_t dt = 0.1;
- for(int n = 0; n < 1000; n++) {
- for(int h = 0; h < nb_heur; h++) {
- blocks[h]->apply_force(dt, blocks[h]->_center_x, blocks[h]->_center_y, 0, 10);
+ for(int n = 0; n < 100000; n++) {
+ for(int i = 0; i < nb_heur; i++) {
+ blocks[i]->apply_force(dt, blocks[i]->_center_x, blocks[i]->_center_y, 0, 0.25);
}
universe.update(dt);
+ if(n%1000 == 0) {
+ char buffer[1024];
+ sprintf(buffer, "/tmp/mash_%06d.fig", n);
+ ofstream os(buffer);
+ universe.print_fig(os);
+ cout << "Wrote " << buffer << endl;
+ }
}
ofstream os("/tmp/mash.fig");
universe.print_fig(os);
+
exit(0);
}