cairo_scale(_context_resource, scale, scale);
cairo_set_source_rgb(_context_resource, 1.0, 1.0, 1.0);
- // cairo_set_source_rgb(_context_resource, 0.0, 0.0, 0.0);
+ cairo_set_line_width (_context_resource, 1.0);
cairo_rectangle(_context_resource, 0, 0, width, height);
delete[] _data;
}
+
+void CanvasCairo::set_line_width(scalar_t w) {
+ cairo_set_line_width (_context_resource, w);
+}
+
void CanvasCairo::set_drawing_color(scalar_t r, scalar_t g, scalar_t b) {
cairo_set_source_rgb(_context_resource, r, g, b);
}
void CanvasCairo::draw_polygon(int filled, int nb, scalar_t *x, scalar_t *y) {
- cairo_set_line_width(_context_resource, 1.0);
cairo_move_to(_context_resource, x[0], y[0]);
for(int n = 0; n < nb; n++) {
cairo_line_to(_context_resource, x[n], y[n]);
void generate_png(Universe *universe, scalar_t scale, FILE *file) {
CanvasCairo canvas(scale, universe->width(), universe->height());
+ canvas.set_line_width(2.0);
universe->draw(&canvas);
canvas.write_png(file);
}
scalar_t object_center_x = delta + (world_width - 2 * delta) * drand48();
scalar_t object_center_y = delta + (world_height - 2 * delta) * drand48();
scalar_t red, green, blue;
- red = 0.75;
+ red = 0.90;
green = red;
blue = red;
delete pol;
const scalar_t scaling = 0.16;
+ CanvasCairo grab_trace(scaling, world_width, world_height);
+
{
char buffer[1024];
sprintf(buffer, "/tmp/universe_%03d_0.png", n);
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;
+ scalar_t xp[n], yp[n];
+ for(int k = 0; k < n; k++) {
+ scalar_t radius = 1/scaling;
+ scalar_t alpha = 2 * M_PI * scalar_t(k) / scalar_t(n);
+ xp[k] = grab_start_x + radius * cos(alpha);
+ 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.draw_polygon(1, n, xp, yp);
+ }
scalar_t dt = 0.1;
for(int i = 0; i < 500; i++) {
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);
+ }
+ */
}
{
FILE *file = fopen(buffer, "w");
generate_png(universe, scaling, file);
}
+
+ {
+ char buffer[1024];
+ sprintf(buffer, "/tmp/grab_trace_%03d.png", n);
+ FILE *file = fopen(buffer, "w");
+ grab_trace.write_png(file);
+ }
}
delete universe;