+static void
+model_init_grid (Model *model)
+{
+ const int num_ropes = 15;
+ const int num_rope_objects = 15;
+ const int num_objects = num_ropes * num_rope_objects;
+ const int num_sticks = num_ropes * (num_rope_objects - 1) +
+ (num_ropes - 1) * num_rope_objects;
+ const int stick_length = 10;
+ const int rope_offset = 10;
+ double x, y;
+ int i, j, index, stick_index;
+
+ model->objects = g_new (Object, num_objects);
+ model->num_objects = num_objects;
+ model->sticks = g_new (Stick, num_sticks);
+ model->num_sticks = num_sticks;
+ model->offsets = g_new (Offset, num_ropes - 1);
+ model->num_offsets = num_ropes - 1;
+
+ for (i = 0; i < num_ropes; i++) {
+ for (j = 0; j < num_rope_objects; j++) {
+ x = 200 + i * rope_offset;
+ y = 40 + j * stick_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) {
+ stick_index = i * num_rope_objects + j;
+ model->sticks[stick_index].a = &model->objects[index];
+ model->sticks[stick_index].b = &model->objects[index + num_rope_objects];
+ model->sticks[stick_index].length = stick_length;
+ }
+
+ if (j + 1 < num_rope_objects) {
+ stick_index =
+ (num_ropes - 1) * num_rope_objects + i * (num_rope_objects - 1) + j;
+ model->sticks[stick_index].a = &model->objects[index];
+ model->sticks[stick_index].b = &model->objects[index + 1];
+ model->sticks[stick_index].length = stick_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;
+}
+