From 804de9eaa678ecf50ab0ed0fbef027fe6dbce414 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Sun, 11 Sep 2016 21:04:24 +0200 Subject: [PATCH] Update. --- generate.cc | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/generate.cc b/generate.cc index 19e1518..28115b1 100644 --- a/generate.cc +++ b/generate.cc @@ -46,13 +46,19 @@ int main(int argc, char **argv) { Polygon *grabbed_polygon; if(argc < 2 || argc > 3) { - cerr << argv[0] << " []" << endl; + cerr << argv[0] << " [ []]" << endl; exit(1); } int nb_pairs = atoi(argv[1]); + char dir[1024] = "/tmp/"; + if(argc > 2) { + strncpy(dir, argv[2], sizeof(dir) / sizeof(char) - 1); + } + + if(argc > 3) { srand48(atoi(argv[1])); } @@ -125,9 +131,10 @@ int main(int argc, char **argv) { { char buffer[1024]; - sprintf(buffer, "/tmp/universe_%03d_0.png", n); + sprintf(buffer, "%s/dyn_%06d_world_0.png", dir, n); FILE *file = fopen(buffer, "w"); generate_png(universe, scaling, file); + fclose(file); } scalar_t grab_relative_x = grabbed_polygon->relative_x(grab_start_x, grab_start_y); @@ -148,8 +155,9 @@ int main(int argc, char **argv) { grab_trace.draw_polygon(1, n, xp, yp); } + const int nb_iterations = 250; scalar_t dt = 0.1; - for(int i = 0; i < 500; i++) { + for(int i = 0; i < nb_iterations; i++) { scalar_t xf = grabbed_polygon->absolute_x(grab_relative_x, grab_relative_y); scalar_t yf = grabbed_polygon->absolute_y(grab_relative_x, grab_relative_y); grabbed_polygon->apply_force(dt, xf, yf, 0.0, -1.0); @@ -173,16 +181,18 @@ int main(int argc, char **argv) { { char buffer[1024]; - sprintf(buffer, "/tmp/universe_%03d_1.png", n); + sprintf(buffer, "%s/dyn_%06d_world_1.png", dir, n); FILE *file = fopen(buffer, "w"); generate_png(universe, scaling, file); + fclose(file); } { char buffer[1024]; - sprintf(buffer, "/tmp/grab_trace_%03d.png", n); + sprintf(buffer, "%s/dyn_%06d_grab.png", dir, n); FILE *file = fopen(buffer, "w"); grab_trace.write_png(file); + fclose(file); } } -- 2.39.5