May I ask why you did not use Tk?

Recently for amusement I was looking for a simple way to plot geometrical shapes (polygons, regular solids, pyramids) in the form of a bzflag world map using perl. The thought experiment took me far and wide through various incantations of mesa, openGL/Perl, Glut, Perl SDL, and more. In the end I kept trying options and finding errors and horrible bugs eventually coming full circle (pun intended) back to Perl/Tk.

You may find some examples of interest using Tk:

  1. TkGnuPlot
  2. Data visualization using Perl/Tk
  3. Some great examples at The Ultimate (well, not quite) Perl/Tk Page!!!
  4. Graphing examples from The Perl Journal: Perl and the Tk Extension

Some code (corrected from non-working code found in Advanced Perl Programming) always makes a nice point:

#!/usr/bin/perl -w use Tk; $top = MainWindow->new(); $canvas = $top->Canvas(width => 600, height => 490)->pack(); # Draw a set of circles along an archimedean spiral # The centers of these circles move along the spiral # (radius of spiral = constant * theta)
$origin_x = 110; $origin_y = 70; # origin of the spiral $PI = 3.1415926535; $circle_radius = 5; # radius of the first circl +e $path_radius = 0; for ($angle = 0; $angle <= 180; $path_radius += 7, $circle_radius += 3, $angle += 4) { # offset of path coordinates: r.cos() and r.sin() # sin() and cos() like their angles in radians (degrees*/90) $path_x = $origin_x + $path_radius * cos ($angle * $PI / 90); $path_y = $origin_y - $path_radius * sin ($angle * $PI / 90); # path_x and path_y are the coordinates of the center of the new # circle. Canvas::create likes top-left and bottom-right corners $canvas->createOval ( $path_x - $circle_radius, $path_y - $circle_radius, $path_x + $circle_radius, $path_y + $circle_radius, -fill => 'yellow' ); $canvas->createLine ( $origin_x, $origin_y, $path_x, $path_y, -fill => 'slategray'); } MainLoop();

SciDude
The first dog barks... all other dogs bark at the first dog.

In reply to Re^2: GD vs. gnuplot by SciDude
in thread GD vs. gnuplot by johnnywang

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.