From: Francois Fleuret Date: Sun, 11 Sep 2016 17:17:59 +0000 (+0200) Subject: Update. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=4754eda0991874c388d8a93517d579ed447d81e9;p=universe.git Update. --- diff --git a/canvas.h b/canvas.h index a12dc74..b12823e 100644 --- a/canvas.h +++ b/canvas.h @@ -15,6 +15,7 @@ class Canvas { public: + virtual void set_line_width(scalar_t w) = 0; virtual void set_drawing_color(scalar_t r, scalar_t g, scalar_t b) = 0; virtual void draw_polygon(int filled, int nb, scalar_t *x, scalar_t *y) = 0; }; diff --git a/canvas_cairo.cc b/canvas_cairo.cc index f4c4acc..4bdcd2b 100644 --- a/canvas_cairo.cc +++ b/canvas_cairo.cc @@ -35,7 +35,7 @@ CanvasCairo::CanvasCairo(scalar_t scale, int width, int height) { cairo_scale(_context_resource, scale, scale); cairo_set_source_rgb(_context_resource, 1.0, 1.0, 1.0); - // cairo_set_source_rgb(_context_resource, 0.0, 0.0, 0.0); + cairo_set_line_width (_context_resource, 1.0); cairo_rectangle(_context_resource, 0, 0, width, height); @@ -48,12 +48,16 @@ CanvasCairo::~CanvasCairo() { delete[] _data; } + +void CanvasCairo::set_line_width(scalar_t w) { + cairo_set_line_width (_context_resource, w); +} + void CanvasCairo::set_drawing_color(scalar_t r, scalar_t g, scalar_t b) { cairo_set_source_rgb(_context_resource, r, g, b); } void CanvasCairo::draw_polygon(int filled, int nb, scalar_t *x, scalar_t *y) { - cairo_set_line_width(_context_resource, 1.0); cairo_move_to(_context_resource, x[0], y[0]); for(int n = 0; n < nb; n++) { cairo_line_to(_context_resource, x[n], y[n]); diff --git a/canvas_cairo.h b/canvas_cairo.h index ab1d6ba..903b555 100644 --- a/canvas_cairo.h +++ b/canvas_cairo.h @@ -23,8 +23,9 @@ class CanvasCairo : public Canvas { public: CanvasCairo(scalar_t scale, int width, int height); - ~CanvasCairo(); + + virtual void set_line_width(scalar_t w); virtual void set_drawing_color(scalar_t r, scalar_t g, scalar_t b); virtual void draw_polygon(int filled, int nb, scalar_t *x, scalar_t *y); virtual void write_png(FILE *file); diff --git a/generate.cc b/generate.cc index 6a8ee69..19e1518 100644 --- a/generate.cc +++ b/generate.cc @@ -31,6 +31,7 @@ using namespace std; void generate_png(Universe *universe, scalar_t scale, FILE *file) { CanvasCairo canvas(scale, universe->width(), universe->height()); + canvas.set_line_width(2.0); universe->draw(&canvas); canvas.write_png(file); } @@ -92,7 +93,7 @@ int main(int argc, char **argv) { scalar_t object_center_x = delta + (world_width - 2 * delta) * drand48(); scalar_t object_center_y = delta + (world_height - 2 * delta) * drand48(); scalar_t red, green, blue; - red = 0.75; + red = 0.90; green = red; blue = red; delete pol; @@ -120,6 +121,8 @@ int main(int argc, char **argv) { const scalar_t scaling = 0.16; + CanvasCairo grab_trace(scaling, world_width, world_height); + { char buffer[1024]; sprintf(buffer, "/tmp/universe_%03d_0.png", n); @@ -129,6 +132,21 @@ int main(int argc, char **argv) { scalar_t grab_relative_x = grabbed_polygon->relative_x(grab_start_x, grab_start_y); scalar_t grab_relative_y = grabbed_polygon->relative_y(grab_start_x, grab_start_y); + // scalar_t grab_previous_x = grab_start_x, grab_previous_y = grab_start_y; + + { + int n = 36; + scalar_t xp[n], yp[n]; + for(int k = 0; k < n; k++) { + scalar_t radius = 1/scaling; + scalar_t alpha = 2 * M_PI * scalar_t(k) / scalar_t(n); + xp[k] = grab_start_x + radius * cos(alpha); + yp[k] = grab_start_y + radius * sin(alpha); + } + grab_trace.set_drawing_color(0.0, 0.0, 0.0); + grab_trace.set_line_width(1.0); + grab_trace.draw_polygon(1, n, xp, yp); + } scalar_t dt = 0.1; for(int i = 0; i < 500; i++) { @@ -136,6 +154,21 @@ int main(int argc, char **argv) { scalar_t yf = grabbed_polygon->absolute_y(grab_relative_x, grab_relative_y); grabbed_polygon->apply_force(dt, xf, yf, 0.0, -1.0); universe->update(dt); + + /* + { + scalar_t xp[2], yp[2]; + xp[0] = grab_previous_x; + yp[0] = grab_previous_y; + xp[1] = xf; + yp[1] = yf; + grab_previous_x = xf; + grab_previous_y = yf; + + grab_trace.set_drawing_color(0.0, 0.0, 0.0); + grab_trace.draw_polygon(1, 2, xp, yp); + } + */ } { @@ -144,6 +177,13 @@ int main(int argc, char **argv) { FILE *file = fopen(buffer, "w"); generate_png(universe, scaling, file); } + + { + char buffer[1024]; + sprintf(buffer, "/tmp/grab_trace_%03d.png", n); + FILE *file = fopen(buffer, "w"); + grab_trace.write_png(file); + } } delete universe;