d71f266dd27581c82276aaf0ff583a430493fa1b
[universe.git] / art.cc
1 #include <iostream>
2 #include <fstream>
3 #include <cmath>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <stdint.h>
7 #include <errno.h>
8 #include <string.h>
9
10 using namespace std;
11
12 #include "misc.h"
13 // #include "task.h"
14 // #include "simple_window.h"
15 #include "universe.h"
16 // #include "retina.h"
17 // #include "manipulator.h"
18
19 int main(int argc, char **argv) {
20
21   {
22     nice(19);
23     scalar_t xs[] = { -28,  28,  28, -28 };
24     scalar_t ys[] = { -28, -28,  28,  28 };
25     Universe universe(1000);
26     int w = 20, h = 20;
27     Polygon *p;
28     for(int x = 0; x < w; x++) for(int y = 0; y < h; y++) {
29       p = new Polygon(1.0, 1.0, 1.0, 0.0, xs, ys, 4);
30       p->set_position(30 + 60 * x, 30 + 60 * y, 0);
31       p->set_speed(0, 0, 0);
32       universe.add_polygon(p);
33     }
34
35     const int nb_projectiles = 15;
36     Polygon *projectiles[nb_projectiles];
37
38     for(int b = 0; b < nb_projectiles; b++) {
39
40       int ne = 100;
41       projectiles[b] = new Polygon(1.0, 0.0, 0.25, 1.0, 0, 0, ne);
42       for(int e = 0; e < ne; e++) {
43         scalar_t alpha = 2 * M_PI * scalar_t(e) / scalar_t(ne);
44         projectiles[b]->set_vertex(e,  200 + 20 * cos(alpha), 200 + 20 * sin(alpha));
45       }
46       projectiles[b]->set_position(67 + 60 * b, -60, 0);
47
48 //       scalar_t xs[] = { -10,  10,  10, -10 };
49 //       scalar_t ys[] = { -80, -80,  80,  80 };
50 //       projectiles[b] = new Polygon(1.0, 0.0, 0.25, 1.0, xs, ys, 4);
51 //       projectiles[b]->set_position(67 + 60 * 6, -60, 0);
52
53       projectiles[b]->set_speed(0, 0, 0);
54       universe.add_polygon(projectiles[b]);
55     }
56
57     for(int n = 0; n < 20000; n++) {
58       if(n%100 == 0) cout << n << endl;
59       for(int b = 0; b < nb_projectiles; b++)
60         projectiles[b]->apply_force(0.01, p->_center_x, p->_center_y, 1, 5);
61 //         projectiles[b]->apply_force(0.01, p->_center_x, p->_center_y, 1, 10);
62       universe.update(0.01);
63     }
64
65     for(int n = 0; n < 10000; n++) universe.update(0.01);
66
67     ofstream os("/tmp/universe.fig");
68     universe.print_fig(os);
69     exit(0);
70   }
71 }