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.initialize(p);
35       universe.add_polygon(p);
36     }
37
38     const int nb_projectiles = 1;
39     Polygon *projectiles[nb_projectiles];
40
41     for(int b = 0; b < nb_projectiles; b++) {
42
43       int ne = 100;
44       projectiles[b] = new Polygon(1.0, 0.0, 0.25, 1.0, 0, 0, ne);
45       for(int e = 0; e < ne; e++) {
46         scalar_t alpha = 2 * M_PI * scalar_t(e) / scalar_t(ne);
47         projectiles[b]->set_vertex(e,  200 + 20 * cos(alpha), 200 + 20 * sin(alpha));
48       }
49       projectiles[b]->set_position(67 + 60 * b, -60, 0);
50
51 //       scalar_t xs[] = { -10,  10,  10, -10 };
52 //       scalar_t ys[] = { -80, -80,  80,  80 };
53 //       projectiles[b] = new Polygon(1.0, 0.0, 0.25, 1.0, xs, ys, 4);
54 //       projectiles[b]->set_position(67 + 60 * 6, -60, 0);
55
56       projectiles[b]->set_speed(0, 0, 0);
57       universe.initialize(projectiles[b]);
58       universe.add_polygon(projectiles[b]);
59     }
60
61     scalar_t dt = 0.01;
62
63     for(int n = 0; n < 1000; n++) {
64       if(n%100 == 0) cout << n << endl;
65       for(int b = 0; b < nb_projectiles; b++) {
66         projectiles[b]->apply_force(dt, p->_center_x, p->_center_y, 1, 5);
67       }
68       universe.update(dt);
69     }
70
71     for(int n = 0; n < 10000; n++) universe.update(dt);
72
73     ofstream os("/tmp/universe.fig");
74     universe.print_fig(os);
75     exit(0);
76   }
77 }