#!/usr/bin/perl -w use strict; use warnings; use Goo::Canvas; use Gtk2 '-init'; use Glib qw(TRUE FALSE); my @results; my $r = 0; my $ang = 0; for my $count (1..25){ for my $z(1..100){ $r += .4; $ang += .062832; my $x = $r * cos $ang; my $y = $r * sin $ang; push @results,$x,$y; } } #print "@results\n"; my $window = Gtk2::Window->new('toplevel'); $window->signal_connect('delete_event' => sub { Gtk2->main_quit; }); $window->set_default_size(680, 600); my $vbox = Gtk2::VBox->new; $vbox->set_border_width(4); $vbox->show; my $hbox = Gtk2::HBox->new(FALSE, 4); $vbox->pack_start($hbox, FALSE, FALSE, 0); $hbox->show; $window->add($vbox); my $swin = Gtk2::ScrolledWindow->new; $swin->set_shadow_type('in'); $vbox->pack_start($swin, 1, 1, 0); my $cwidth = 1000; my $cheight = 1000; my ($canvas,$root,$group) = get_canvas(); # Zoom my $z = Gtk2::Label->new("Zoom:"); $hbox->pack_start($z, FALSE, FALSE, 0); $z->show; my $adj = Gtk2::Adjustment->new(1, 0.05, 100, 0.05, 0.5, 0.5); my $sb = Gtk2::SpinButton->new($adj, 0, 2); $adj->signal_connect("value-changed", \&zoom_changed, $canvas); $sb->set_size_request(60, -1); $hbox->pack_start($sb, FALSE, FALSE, 10); $sb->show; # Create PDF + my $bpdf = Gtk2::Button->new_with_label('Write PDF'); + $hbox->pack_start($bpdf, FALSE, FALSE, 0); + $bpdf->show; + $bpdf->signal_connect("clicked", \&write_pdf_clicked, $canvas); + $window->show_all(); &draw(); Gtk2->main; sub get_canvas{ my $canvas = Goo::Canvas->new(); $canvas->set_size_request(600, 450); # minimum size on screen $canvas->set_bounds(0, 0, $cwidth, $cheight); # scrollregion $swin->add($canvas); my $root = $canvas->get_root_item(); $canvas->signal_connect('button-press-event', \&on_can_button_press); my $rect = Goo::Canvas::Rect->new( $root, 0, 0, $cwidth, $cheight, 'line-width' => 1, 'fill-color' => 'black' ); $rect->lower; my $g = Goo::Canvas::Group->new($root); $g->translate(310,300); return ($canvas,$root,$g); } sub draw{ my $points = Goo::Canvas::Points->new(\@results); my $poly = Goo::Canvas::Polyline->new( $group, FALSE, undef, # points need to be set after creation 'stroke-color' => 'pink', # 'fill_color_rgba' => 0xff00ffcc, 'line-width' => 15, ); #setting after line creation, sets the 'points' property by name $poly->set(points => $points); # add some action Glib::Timeout->add (50, sub { $group->scale(1.001,1.001); $group->rotate(-20,0,0); #angle, rot_center_x, rot_cente +r_y #$group->translate(15,15); #make drunk friends puke :-) return 1; }); return 0; } sub write_pdf_clicked { my ($but, $canvas) = @_; print "Write PDF...\n"; my $scale = $adj->get_value; print "scale->$scale\n"; my $surface = Cairo::PdfSurface->create("$0-$scale.pdf", $scale*$cwidth, $scale*$cheight); my $cr = Cairo::Context->create($surface); # needed to save scaled version $cr->scale($scale, $scale); $canvas->render($cr, undef, 1); $cr->show_page; print "done\n"; return TRUE; } sub zoom_changed { my ($adj, $canvas) = @_; my $scale = $adj->get_value; $canvas->set_scale($scale); # zoom from 0,0 ...like Gnome2::Canvas's set_center_scroll_region +(FALSE); $canvas->scroll_to (0,0); }

In reply to Goo'ey Waves of Goo_ness by zentara

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.