Re: [Vala] How to make brownian tree in vala?



Am 12.06.2010 04:26, san hoi wrote:
http://rosettacode.org/wiki/Brownian_tree

I look for graphic library like javascript+canvas.

A simple Cairo context should be sufficient for this task:

------------------------------------------------------------------------------
/* Compile with: valac brownian-tree.vala --pkg gtk+-2.0 */

using Gtk;
using Cairo;

void draw_brownian_tree (Context cr) {
        cr.set_source_rgb (0, 0, 0);
        cr.rectangle (50, 50, 10, 10);
        cr.fill ();
        // ...
        // http://www.tortall.net/mu/wiki/CairoTutorial
        // http://valadoc.org/cairo/Cairo.Context.html
}

int main (string[] args) {
        Gtk.init (ref args);

        var window = new Window (WindowType.TOPLEVEL);
        window.title = "Brownian Tree";
        window.destroy.connect (Gtk.main_quit);
        var drawing_area = new DrawingArea ();
        drawing_area.set_size_request (400, 400);
        drawing_area.expose_event.connect (() => {
                draw_brownian_tree (Gdk.cairo_create (drawing_area.window));
                return false;
        });
        window.add (drawing_area);
        window.show_all ();

        Gtk.main ();
        return 0;
}
------------------------------------------------------------------------------

Best regards,

Frederik



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]