Angharad has asked for the wisdom of the Perl Monks concerning the following question:

Hi people
I am wanting to create a venn diagram and am looking at using the GD.pm package in order to do so.
Is this a good graphics package to use? And if so, would anyone know of any examples I could take a look at? I've looked around but haven't found any so far - I would like to write the program myself but I feel I would benefit from working from a few simple examples - particularly as I have never used a graphics package before.
Or perhaps GD.pm doesnt cut it - in which case, could I ask for advice as to what else I could use?
Any pointers in the right direction much appreciated.
  • Comment on need advice on how to create venn diagram program

Replies are listed 'Best First'.
Re: need advice on how to create venn diagram program
by BrowserUk (Patriarch) on Nov 03, 2006 at 11:33 UTC

    This might get you started with the GD route. Whether it's the right tool depends upon what you are going to do with the image once you've created it.

    #! perl -slw use strict; use GD; ## Create a true color (24-bit) image my $img = GD::Image->new( 600, 300, 1 ); ## Create some colors ## Background my $white = $img->colorAllocate( 255, 255, 255 ); ## Solid Red my $red100 = $img->colorAllocate( 255, 0, 0 ); ## 25% lalpha blending red my $red25 = $img->colorAllocateAlpha( 255, 0, 0, 31 ); ## Solid green my $green100 = $img->colorAllocate( 0, 255, 0 ); ## 25%alpha blending green my $green25 = $img->colorAllocateAlpha( 0, 255, 0, 31 ); ## Alpha blending off $img->alphaBlending( 0 ); ## Fill the background $img->fill( 0, 0, $white ); ## Draw red & green $img->filledEllipse( 200, 150, 250, 250, $red100 ); ## overlapping circles $img->filledEllipse( 400, 150, 250, 250, $green100 ); ## Alpha blending on $img->alphaBlending( 1 ); ## Redraw both $img->filledEllipse( 200, 150, 250, 250, $red25 ); ## This time blended $img->filledEllipse( 400, 150, 250, 250, $green25 ); ## Open a file for binary output open PNG, '>:raw', '582047.png' or die $!; ## Save the image as png print PNG $img->png; close PNG; ## Display it (assumes windows and a suitable file association) system '582047.png';

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: need advice on how to create venn diagram program
by davorg (Chancellor) on Nov 03, 2006 at 10:51 UTC

    What type of output do you want to create? If it was me, I think I'd look at creating the diagrams in SVG using SVG.pm.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      Hi, thanks for your reply. I just want a graphical representation of a venn diagram, complete with overlaps (if there are any) and some colouring to to indicate certain features. I shall have a look at the SVG.pm. :)
Re: need advice on how to create venn diagram program
by zentara (Cardinal) on Nov 03, 2006 at 13:50 UTC
    See my responses in Drawing venn diagrams , where I do Venn in Tk, Gtk2 and Tk::Zinc. They are draggable. Gtk2 or Zinc is the nicest because they have semi-transparency, whereas Tk just has bitmap stipples.

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: need advice on how to create venn diagram program
by planetscape (Chancellor) on Nov 03, 2006 at 21:26 UTC

    Wikipedia seems very helpful on the subject of Venn diagrams. Included in the article are links to external sites such as VennDiagrams and VennDiagram.tk, the latter relying on SVG, so you could look at the source of those programs to assist you with your own.

    When this question came up in the past, I'd have sworn there was an IBM developerWorks article on creating Venn Diagrams with SVG, but I can't for the life of me find it now...

    HTH,

    planetscape