Created
September 1, 2011 12:17
-
-
Save delamonpansie/1186053 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Graphics.UI.Gtk | |
import Graphics.Rendering.Cairo | |
render = do | |
moveTo 0 0 | |
sequence_ $ replicate 50000 (relLineTo 0.01 0.01) | |
stroke | |
main :: IO () | |
main = do | |
initGUI | |
window <- windowNew | |
canvas <- drawingAreaNew | |
canvas `onExpose` (\x -> do win <- widgetGetDrawWindow canvas | |
renderWithDrawable win render | |
mainQuit | |
return True) | |
containerAdd window canvas | |
window `onDestroy` mainQuit | |
widgetShowAll window | |
mainGUI | |
------------------------------------------------------------------------------ | |
#include <gtk/gtk.h> | |
#include <cairo.h> | |
#include <stdlib.h> | |
static void | |
paint (GtkWidget *widget, GdkEventExpose *eev, gpointer data) | |
{ | |
gint width, height; | |
gint i; | |
cairo_t *cr; | |
width = widget->allocation.width; | |
height = widget->allocation.height; | |
cr = gdk_cairo_create (widget->window); | |
cairo_move_to(cr, 0, 0); | |
for(i = 1; i < 50000; i++) | |
cairo_rel_line_to(cr, 0.01, 0.01); | |
cairo_stroke(cr); | |
cairo_destroy(cr); | |
exit(0); | |
} | |
gint | |
main (gint argc, gchar **argv) | |
{ | |
GtkWidget *window; | |
GtkWidget *canvas; | |
gtk_init (&argc, &argv); | |
window = gtk_window_new (GTK_WINDOW_TOPLEVEL); | |
g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (gtk_main_quit), NULL); | |
canvas = gtk_drawing_area_new (); | |
g_signal_connect (G_OBJECT (canvas), "expose-event", G_CALLBACK (paint), NULL); | |
gtk_container_add (GTK_CONTAINER (window), canvas); | |
gtk_widget_show_all (window); | |
gtk_main (); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment