#include koch_sala_elementas(cairo_t* cr, double stx, double sty, int n) { if (n > 0) { n--; stx = stx/ 4; sty = sty/ 4; koch_sala_elementas(cr, stx, sty, n); koch_sala_elementas(cr, sty, -stx, n); koch_sala_elementas(cr, stx, sty, n); koch_sala_elementas(cr, -2*sty, 2*stx, n); koch_sala_elementas(cr, stx, sty, n); koch_sala_elementas(cr, sty, -stx, n); koch_sala_elementas(cr, stx, sty, n); } else { cairo_rel_line_to(cr, stx, sty); cairo_rel_line_to(cr, sty, -stx); cairo_rel_line_to(cr, stx, sty); cairo_rel_line_to(cr, -2*sty, 2*stx); cairo_rel_line_to(cr, stx, sty); cairo_rel_line_to(cr, sty, -stx); cairo_rel_line_to(cr, stx, sty); } } koch_sala(cairo_t* cr, int n) { cairo_move_to(cr, 0.2, 0.2); koch_sala_elementas(cr, 0.1, 0, n); koch_sala_elementas(cr, 0, 0.1, n); koch_sala_elementas(cr, -0.1, 0, n); koch_sala_elementas(cr, 0, -0.1, n); cairo_close_path(cr); cairo_fill(cr); } expose(GtkWidget *widget, GdkEventExpose *event, gpointer data) { cairo_t* cr = gdk_cairo_create(widget-> window); cairo_scale(cr, widget->allocation.width, widget->allocation.height); cairo_set_line_width (cr, 0.02); koch_sala(cr, 4); cairo_show_page(cr); cairo_destroy(cr); return TRUE; } int main (int argc, char **argv) { gtk_init(&argc, &argv); GtkWidget *win = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(win, "delete_event", gtk_main_quit, NULL); GtkWidget* area = gtk_drawing_area_new(); gtk_widget_set_size_request (area, 200, 200); g_signal_connect(G_OBJECT(area), "expose_event", G_CALLBACK(expose), NULL); gtk_container_add(GTK_CONTAINER(win), area); gtk_widget_show_all(win); gtk_main(); return 0; }