Update.
authorFrancois Fleuret <francois@fleuret.org>
Sat, 17 Sep 2016 12:13:33 +0000 (14:13 +0200)
committerFrancois Fleuret <francois@fleuret.org>
Sat, 17 Sep 2016 12:13:33 +0000 (14:13 +0200)
generate.cc

index f851694..999c753 100644 (file)
@@ -34,7 +34,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);
+  canvas.set_line_width(1.0 / scale);
   universe->draw(&canvas);
   canvas.write_png(file);
 }
@@ -46,7 +46,10 @@ int main(int argc, char **argv) {
   const scalar_t grab_start_y = world_height * 0.75;
   const int nb_blocks = 1;
   const scalar_t block_size = 80;
-  const int nb_iterations = 250;
+
+  const scalar_t dt = 0.1;
+  const int nb_steps = 5;
+  const int nb_iterations_per_steps = 20;
 
   Universe *universe;
   Polygon *grabbed_polygon;
@@ -86,17 +89,17 @@ int main(int argc, char **argv) {
 
         do {
           scalar_t x[] = {
-            - block_size * 0.5,
-            + block_size * 0.5,
-            + block_size * 0.5,
-            - block_size * 0.5,
+            - block_size * 0.4,
+            + block_size * 0.4,
+            + block_size * 0.4,
+            - block_size * 0.4,
           };
 
           scalar_t y[] = {
-            - block_size * 0.5,
-            - block_size * 0.5,
-            + block_size * 0.5,
-            + block_size * 0.5,
+            - block_size * 0.6,
+            - block_size * 0.6,
+            + block_size * 0.6,
+            + block_size * 0.6,
           };
 
           scalar_t delta = block_size / sqrt(2.0);
@@ -139,17 +142,8 @@ int main(int argc, char **argv) {
       mkdir(buffer, 0777);
     }
 
-    {
-      char buffer[1024];
-      sprintf(buffer, "%s/%03d/dyn_%06d_world_0.png", dir, n/1000, 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);
     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;
@@ -161,31 +155,25 @@ int main(int argc, char **argv) {
         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.set_line_width(2.0);
       grab_trace.draw_polygon(1, n, xp, yp);
     }
 
-    scalar_t dt = 0.1;
-    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);
-      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);
-        }
-      */
+    for(int s = 0; s < nb_steps; s++) {
+      {
+        char buffer[1024];
+        sprintf(buffer, "%s/%03d/dyn_%06d_world_%03d.png", dir, n/1000, n, s);
+        FILE *file = fopen(buffer, "w");
+        generate_png(universe, scaling, file);
+        fclose(file);
+      }
+
+      for(int i = 0; i < nb_iterations_per_steps; 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);
+        universe->update(dt);
+      }
     }
 
     {
@@ -195,14 +183,6 @@ int main(int argc, char **argv) {
       grab_trace.write_png(file);
       fclose(file);
     }
-
-    {
-      char buffer[1024];
-      sprintf(buffer, "%s/%03d/dyn_%06d_world_1.png", dir, n/1000, n);
-      FILE *file = fopen(buffer, "w");
-      generate_png(universe, scaling, file);
-      fclose(file);
-    }
   }
 
   delete universe;