X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=universe.cc;h=92b7a1b702558bc806c3efa719daee6f1dd22626;hb=8697ab57c9138aa2bb1657a971e4c2cc5e4a1606;hp=90f93caf309bd046e096bf23a375239f0c1c72b8;hpb=53885334edba4b9d3c4ee6d10fbfdd7e8a30d73b;p=universe.git diff --git a/universe.cc b/universe.cc index 90f93ca..92b7a1b 100644 --- a/universe.cc +++ b/universe.cc @@ -7,7 +7,7 @@ #include "universe.h" Universe::Universe(int nb_max_polygons, - scalar_t xmax, scalar_t ymax) : _xmax(xmax), _ymax(ymax), + scalar_t width, scalar_t height) : _width(width), _height(height), _nb_max_polygons(nb_max_polygons), _nb_polygons(0) { _polygons = new Polygon *[_nb_max_polygons]; for(int n = 0; n < _nb_max_polygons; n++) _polygons[n] = 0; @@ -35,7 +35,7 @@ void Universe::add_polygon(Polygon *p) { } _polygons[_nb_polygons++] = p; } else { - cerr << "To many polygons!" << endl; + cerr << "Too many polygons!" << endl; exit(1); } } @@ -104,7 +104,7 @@ bool Universe::update(scalar_t dt) { bool result = false; apply_collision_forces(dt); for(int n = 0; n < _nb_polygons; n++) if(_polygons[n]) { - _polygons[n]->apply_border_forces(dt, _xmax, _ymax); + _polygons[n]->apply_border_forces(dt, _width, _height); result |= _polygons[n]->update(dt); } return result; @@ -116,23 +116,50 @@ Polygon *Universe::pick_polygon(scalar_t x, scalar_t y) { return 0; } -void Universe::print_fig(ostream &os) { - os << "#FIG 3.2" << endl; - os << "Portrait" << endl; - os << "Center" << endl; - os << "Metric" << endl; - os << "A4 " << endl; - os << "100.00" << endl; - os << "Single" << endl; - os << "-2" << endl; - os << "1200 2" << endl; - for(int n = 0; n < _nb_polygons; n++) if(_polygons[n]) _polygons[n]->print_fig(os); +void Universe::print_xfig(XFigTracer *tracer) { + for(int n = 0; n < _nb_polygons; n++) { + if(_polygons[n]) { + _polygons[n]->color_xfig(tracer); + } + } + for(int n = 0; n < _nb_polygons; n++) { + if(_polygons[n]) { + _polygons[n]->print_xfig(tracer); + } + } } +#ifdef X11_SUPPORT void Universe::draw(SimpleWindow *window) { - for(int n = 0; n < _nb_polygons; n++) if(_polygons[n]) _polygons[n]->draw(window); - for(int n = 0; n < _nb_polygons; n++) if(_polygons[n]) _polygons[n]->draw_contours(window); + for(int n = 0; n < _nb_polygons; n++) { + if(_polygons[n]) { + _polygons[n]->draw(window); + } + } + + for(int n = 0; n < _nb_polygons; n++) { + if(_polygons[n]) { + _polygons[n]->draw_contours(window); + } + } +} +#endif + +#ifdef CAIRO_SUPPORT +void Universe::draw(cairo_t *context_resource) { + for(int n = 0; n < _nb_polygons; n++) { + if(_polygons[n]) { + _polygons[n]->draw(context_resource); + } + } + + for(int n = 0; n < _nb_polygons; n++) { + if(_polygons[n]) { + _polygons[n]->draw_contours(context_resource); + } + } } +#endif void Universe::apply_collision_forces(scalar_t dt) { const int nb_axis = 2;