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