model->sticks[i * 2 + 1].length = random() % 20 + 20;
}
}
-
- model->anchor_object = NULL;
}
static void
model->sticks[i].length = stick_length;
}
}
-
- model->anchor_object = NULL;
}
static void
model->offsets[0].objects[i] = &model->objects[i * num_rope_objects];
}
-
- model->anchor_object = NULL;
}
static void
model_init_grid (Model *model)
{
- const int num_ropes = 4;
- const int num_rope_objects = 4;
+ const int num_ropes = 8;
+ const int num_rope_objects = 8;
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 = 20;
const int rope_offset = 20;
- double x, y;
- int i, j, index, string_index;
+ Object *object;
+ String *string;
+ int i, j;
memset (model, 0, sizeof *model);
model->objects = g_new (Object, num_objects);
model->offsets[0].dx = rope_offset;
model->offsets[0].dy = 0;
+ object = model->objects;
+ string = model->strings;
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;
- object_init (&model->objects[index], x, y, 1);
+ object_init (object, 200 + i * rope_offset, 40 + j * string_length, 1);
- 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)
+ string_init (string++,
+ object, object + num_rope_objects, string_length);
+ if (j + 1 < num_rope_objects)
+ string_init (string++, object, object + 1, string_length);
+ object++;
}
model->offsets[0].objects[i] = &model->objects[i * num_rope_objects];
}
-
- model->anchor_object = NULL;
}
static void
}
}
+static void
+model_init_dock (Model *model)
+{
+ const int num_objects = 8;
+ const int num_spacers = (num_objects - 1) * (num_objects - 2) / 2;
+ const int num_springs = num_objects - 1;
+ const int distance = 30;
+ double x, y;
+ 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_rectangle (&model->polygons[0], -400, 300, 1400, 350);
+
+ model->anchors[0].x = 300;
+ model->anchors[0].y = 300;
+ model->anchors[0].object = &model->objects[0];
+
+ object = model->objects;
+ spring = model->springs;
+ spacer = model->spacers;
+ for (i = 0; i < num_objects; i++, object++) {
+ x = 200 + i * distance / 3;
+ y = 40;
+ object_init (object, x, y, 1);
+ if (i == 0)
+ continue;
+ spring_init (spring++,
+ &model->objects[0],
+ &model->objects[i],
+ distance);
+ for (j = 1; j < num_objects - i; j++) {
+ spacer_init (spacer++, object, object + j, distance);
+ }
+ }
+}
+
typedef struct _Color Color;
struct _Color {
double red, green, blue;
if (event->button != 1)
return TRUE;
- closure->model->anchor_position.x = event->x;
- closure->model->anchor_position.y = event->y;
- closure->model->anchor_object = model_find_nearest (closure->model,
- event->x, event->y);
+ closure->model->mouse_anchor.x = event->x;
+ closure->model->mouse_anchor.y = event->y;
+ closure->model->mouse_anchor.object =
+ model_find_nearest (closure->model, event->x, event->y);
return TRUE;
}
if ((event->state & GDK_BUTTON1_MASK) == 0)
return TRUE;
- closure->model->anchor_object = NULL;
+ closure->model->mouse_anchor.object = NULL;
return TRUE;
}
gdk_window_get_pointer (event->window, &x, &y, &state);
- closure->model->anchor_position.x = x + 0.5;
- closure->model->anchor_position.y = y + 0.5;
+ closure->model->mouse_anchor.x = x + 0.5;
+ closure->model->mouse_anchor.y = y + 0.5;
return TRUE;
}
{ "Curtain", model_init_curtain },
{ "Grid", model_init_grid },
{ "Molecule", model_init_molecule },
- { "Wobbly", model_init_wobbly }
+ { "Wobbly", model_init_wobbly },
+ { "Dock", model_init_dock }
};
GtkTreeIter iter;
GtkWidget *model_combo;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- gtk_window_set_title (GTK_WINDOW (window), "Akamaru");
+ gtk_window_set_title (GTK_WINDOW (window), "赤丸");
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_main_quit), &window);