X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=polygon.cc;h=35bbd9cbe0c429aab6ba7bd5eff0d7dc6a089123;hb=599bf3fa2eb01b05ec677b628e65adb2fe4f91c3;hp=2ae238d3c1c39010c56da46953988655bfca6e58;hpb=3e51d77116e49ba279a6cbbf1dbbc893c4117eb4;p=universe.git diff --git a/polygon.cc b/polygon.cc index 2ae238d..35bbd9c 100644 --- a/polygon.cc +++ b/polygon.cc @@ -2,9 +2,13 @@ // Written and (C) by Francois Fleuret // Contact for comments & bug reports +#include + #include #include "polygon.h" +using namespace std; + static const scalar_t dl = 20.0; static const scalar_t repulsion_constant = 0.2; static const scalar_t dissipation = 0.5; @@ -47,6 +51,7 @@ Polygon *Polygon::clone() { return new Polygon(_mass, _red, _green, _blue, _relative_x, _relative_y, _nb_vertices); } +#ifdef XFIG_SUPPORT void Polygon::color_xfig(XFigTracer *tracer) { tracer->add_color(int(255 * _red), int(255 * _green), int(255 * _blue)); } @@ -55,7 +60,9 @@ void Polygon::print_xfig(XFigTracer *tracer) { tracer->draw_polygon(int(255 * _red), int(255 * _green), int(255 * _blue), _nb_vertices, _x, _y); } +#endif +#ifdef X11_SUPPORT void Polygon::draw(SimpleWindow *window) { window->color(_red, _green, _blue); int x[_nb_vertices], y[_nb_vertices]; @@ -73,8 +80,21 @@ void Polygon::draw_contours(SimpleWindow *window) { y[n] = int(_y[n]); } window->color(0.0, 0.0, 0.0); - for(int n = 0; n < _nb_vertices; n++) + // window->color(1.0, 1.0, 1.0); + for(int n = 0; n < _nb_vertices; n++) { window->draw_line(x[n], y[n], x[(n+1)%_nb_vertices], y[(n+1)%_nb_vertices]); + } +} +#endif + +void Polygon::draw(Canvas *canvas) { + canvas->set_drawing_color(_red, _green, _blue); + canvas->draw_polygon(1, _nb_vertices, _x, _y); +} + +void Polygon::draw_contours(Canvas *canvas) { + canvas->set_drawing_color(0.0, 0.0, 0.0); + canvas->draw_polygon(0, _nb_vertices, _x, _y); } void Polygon::set_vertex(int k, scalar_t x, scalar_t y) { @@ -179,7 +199,9 @@ void Polygon::initialize(int nb_polygons) { _nb_polygons = nb_polygons; - a = _relative_x[_nb_vertices - 1] * _relative_y[0] - _relative_x[0] * _relative_y[_nb_vertices - 1]; + a = _relative_x[_nb_vertices - 1] * _relative_y[0] + - _relative_x[0] * _relative_y[_nb_vertices - 1]; + for(int n = 0; n < _nb_vertices - 1; n++) a += _relative_x[n] * _relative_y[n+1] - _relative_x[n+1] * _relative_y[n]; a *= 0.5; @@ -489,4 +511,3 @@ bool Polygon::collide(Polygon *p) { return false; } -