2 ////////////////////////////////////////////////////////////////////
5 // Written by Francois Fleuret //
6 // Contact <francois.fleuret@idiap.ch> for comments & bug reports //
9 ////////////////////////////////////////////////////////////////////
24 #include "simple_window.h"
28 #include "manipulator.h"
29 #include "intelligence.h"
30 #include "canvas_cairo.h"
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);
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;
43 Universe *universe = new Universe(10, world_width, world_height);
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,
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,
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);
66 FILE *file = fopen("universe1.png", "w");
67 generate_png(universe, 0.25, file);
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);
77 FILE *file = fopen("universe2.png", "w");
78 generate_png(universe, 0.25, file);