From a64a278f99ec7cac490217370ccd8b59a7bef33d Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Fri, 10 Jul 2009 10:14:59 +0200 Subject: [PATCH] Initial commit. --- mash.cc | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 mash.cc diff --git a/mash.cc b/mash.cc new file mode 100644 index 0000000..6eafd6c --- /dev/null +++ b/mash.cc @@ -0,0 +1,72 @@ +// -*- compile-command:"g++ -lX11 -Wall -g -O3 -o mash misc.o universe.o polygon.o mash.cc -L/usr/X11R6/lib/"; -*- + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +#include "misc.h" +#include "universe.h" + +int main(int argc, char **argv) { + int nb_heur = 100; + int w = 1000, h = 1000; + Universe universe(nb_heur + 1, w, h); + + { + int nb = 100; + scalar_t xs[nb], ys[nb]; + for(int k = 0; k < nb; k++) { + scalar_t alpha, radius; + if(k < nb/2) { + alpha = - (M_PI / scalar_t(nb/2)) * k; + radius = 400; + } else { + alpha = - (M_PI / scalar_t(nb/2)) * (nb - k - 1); + radius = 350; + } + xs[k] = scalar_t(w)/2 + radius * cos(-alpha); + 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->set_position(scalar_t(w/2), scalar_t(h) * 0.75, 0); + p->set_speed(0, 0, 0); + universe.initialize(p); + 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); + 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]); + } + + scalar_t dt = 0.01; + + 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); + } + universe.update(dt); + } + + ofstream os("/tmp/mash.fig"); + universe.print_fig(os); + exit(0); +} -- 2.39.5