62b61ecfc5baa189d1ef394038a3a84572c66c4e
[universe.git] / generate.cc
1
2 ////////////////////////////////////////////////////////////////////
3 // START_IP_HEADER                                                //
4 //                                                                //
5 // Written by Francois Fleuret                                    //
6 // Contact <francois.fleuret@idiap.ch> for comments & bug reports //
7 //                                                                //
8 // END_IP_HEADER                                                  //
9 ////////////////////////////////////////////////////////////////////
10
11 #include <iostream>
12 #include <fstream>
13 #include <cmath>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <stdint.h>
17 #include <errno.h>
18 #include <string.h>
19
20 using namespace std;
21
22 #include "misc.h"
23 #include "task.h"
24 #include "simple_window.h"
25 #include "universe.h"
26 #include "plotter.h"
27 #include "retina.h"
28 #include "manipulator.h"
29 #include "intelligence.h"
30 #include "canvas_cairo.h"
31
32 void generate_png(Universe *universe, scalar_t scale, FILE *file) {
33   CanvasCairo canvas(scale, universe->width(), universe->height());
34   universe->draw(&canvas);
35   canvas.write_png(file);
36 }
37
38 int main(int argc, char **argv) {
39   scalar_t world_width = 400;
40   scalar_t world_height = 400;
41   scalar_t square_size = 100;
42
43   Universe *universe = new Universe(10, world_width, world_height);
44
45   scalar_t x[] = {
46     world_width * 0.5 - square_size * 0.5,
47     world_width * 0.5 + square_size * 0.5,
48     world_width * 0.5 + square_size * 0.5,
49     world_width * 0.5 - square_size * 0.5,
50   };
51
52   scalar_t y[] = {
53     world_height * 0.5 - square_size * 0.5,
54     world_height * 0.5 - square_size * 0.5,
55     world_height * 0.5 + square_size * 0.5,
56     world_height * 0.5 + square_size * 0.5,
57   };
58
59   Polygon *pol = new Polygon(0.5, 1.0, 1.0, 0.0, x, y, 4);
60   pol->set_position(world_width * 0.5, world_height * 0.5, M_PI/3);
61   pol->set_speed(0, 0, 0);
62   universe->initialize_polygon(pol);
63   universe->add_polygon(pol);
64
65   {
66     FILE *file = fopen("universe1.png", "w");
67     generate_png(universe, 0.25, file);
68   }
69
70   scalar_t hand_x = world_width * 0.5;
71   scalar_t hand_y = world_height * 0.5;
72   Polygon *grabbed_polygon = universe->pick_polygon(hand_x, hand_y);
73   scalar_t grab_relative_x = grabbed_polygon->relative_x(hand_x, hand_y);
74   scalar_t grab_relative_y = grabbed_polygon->relative_y(hand_x, hand_y);
75
76   {
77     FILE *file = fopen("universe2.png", "w");
78     generate_png(universe, 0.25, file);
79   }
80
81   delete universe;
82 }