+static void
+model_init_grid (Model *model)
+{
+ const int num_ropes = 10;
+ const int num_rope_objects = 10;
+ const int num_objects = num_ropes * num_rope_objects;
+ const int num_strings = num_ropes * (num_rope_objects - 1) +
+ (num_ropes - 1) * num_rope_objects;
+ const int string_length = 10;
+ const int rope_offset = 10;
+ double x, y;
+ int i, j, index, string_index;
+
+ memset (model, 0, sizeof *model);
+ model->objects = g_new (Object, num_objects);
+ model->num_objects = num_objects;
+ model->strings = g_new (String, num_strings);
+ model->num_strings = num_strings;
+ model->offsets = g_new (Offset, num_ropes - 1);
+ model->num_offsets = num_ropes - 1;
+ model_init_polygons (model);
+
+ for (i = 0; i < num_ropes; i++) {
+ for (j = 0; j < num_rope_objects; j++) {
+ x = 200 + i * rope_offset;
+ y = 40 + j * string_length;
+ index = i * num_rope_objects + j;
+ model->objects[index].position.x = x;
+ model->objects[index].position.y = y;
+ model->objects[index].previous_position.x = x;
+ model->objects[index].previous_position.y = y;
+
+ if (i + 1 < num_ropes) {
+ string_index = i * num_rope_objects + j;
+ model->strings[string_index].a = &model->objects[index];
+ model->strings[string_index].b = &model->objects[index + num_rope_objects];
+ model->strings[string_index].length = string_length;
+ }
+
+ if (j + 1 < num_rope_objects) {
+ string_index =
+ (num_ropes - 1) * num_rope_objects + i * (num_rope_objects - 1) + j;
+ model->strings[string_index].a = &model->objects[index];
+ model->strings[string_index].b = &model->objects[index + 1];
+ model->strings[string_index].length = string_length;
+ }
+ }
+
+ if (i + 1 < num_ropes) {
+ model->offsets[i].a = &model->objects[i * num_rope_objects];
+ model->offsets[i].b = &model->objects[(i + 1) * num_rope_objects];
+ model->offsets[i].dx = rope_offset;
+ model->offsets[i].dy = 0;
+ }
+ }
+
+ model->anchor_object = NULL;
+}
+
+static void
+model_fini (Model *model)
+{
+ g_free (model->objects);
+ g_free (model->sticks);
+ g_free (model->strings);
+ g_free (model->offsets);
+ memset (model, 0, sizeof *model);
+}
+