- const int num_objects = num_items + 1;
- const int num_spacers = (num_objects - 1) * (num_objects - 2) / 2;
- const int num_springs = num_objects - 1;
- int i, j;
- Object *object;
- Spring *spring;
- Spacer *spacer;
-
- memset (model, 0, sizeof *model);
- model->objects = g_new (Object, num_objects);
- model->num_objects = num_objects;
- model->springs = g_new (Spring, num_springs);
- model->num_springs = num_springs;
- model->spacers = g_new (Spacer, num_spacers);
- model->num_spacers = num_spacers;
- model->anchors = g_new (Anchor, 1);
- model->num_anchors = 1;
- model->k = 0.1;
-
- model->polygons = g_new (Polygon, 1);
- model->num_polygons = 1;
- polygon_init_enclosing_rectangle (&model->polygons[0], 0, 0, 1024 - 50, y);
-
- model->anchors[0].x = x;
- model->anchors[0].y = y;
- model->anchors[0].object = &model->objects[0];
-
- object_init (&model->objects[0], x, y, 20);
-
- object = &model->objects[1];
- spring = model->springs;
- spacer = model->spacers;
-
- for (i = 1; i < num_objects; i++, object++) {
- object_init (&model->objects[i], 200 + i * spacing / 2, 300, 3);
- spring_init (spring++, &model->objects[0], object, spacing);
- for (j = 1; j < num_objects - i; j++) {
- spacer_init (spacer++, object, object + j, spacing);
- }
- }
+ const int num_objects = num_items + 1;
+ const int num_spacers = (num_objects - 1) * (num_objects - 2) / 2;
+ const int num_springs = num_objects - 1;
+ const int spread = spacing + 20;
+ int i, j, left_edge;
+ Object *object;
+ Spring *spring;
+ Spacer *spacer;
+
+ memset (model, 0, sizeof *model);
+ model->objects = g_new (Object, num_objects);
+ model->num_objects = num_objects;
+ model->springs = g_new (Spring, num_springs);
+ model->num_springs = num_springs;
+ model->spacers = g_new (Spacer, num_spacers);
+ model->num_spacers = num_spacers;
+ model->anchors = g_new (Anchor, 1);
+ model->num_anchors = 1;
+ model->k = 0.1;
+
+ model->polygons = g_new (Polygon, 1);
+ model->num_polygons = 1;
+ polygon_init_enclosing_rectangle (&model->polygons[0],
+ 0, 0, width - 50, height - 50);
+
+ model->anchors[0].x = width / 2;
+ model->anchors[0].y = height - 50;
+ model->anchors[0].object = &model->objects[0];
+
+ object_init (&model->objects[0],
+ model->anchors[0].x, model->anchors[0].y, 0);
+
+ object = &model->objects[1];
+ spring = model->springs;
+ spacer = model->spacers;
+ left_edge = (width - (num_items - 1) * spread) / 2;
+
+ for (i = 1; i < num_objects; i++, object++) {
+ object_init (&model->objects[i],
+ left_edge + (i - 1) * spread, height - 100, 1);
+ spring_init (spring++, &model->objects[0], object, spacing);
+ for (j = 1; j < num_objects - i; j++) {
+ spacer_init (spacer++, object, object + j, spacing);
+ }
+ }