annotate not-used/svgExample.pl @ 81:6adb5da55d18 laserkard

getting color select working
author Robert McIntyre <rlm@mit.edu>
date Sun, 25 Jul 2010 05:45:56 -0400
parents 4ebd94bfecda
children
rev   line source
rlm@78 1 #!/usr/bin/perl -w
rlm@78 2 use strict;
rlm@78 3 use SVG;
rlm@78 4
rlm@78 5 # create an SVG object
rlm@78 6 my $svg= SVG->new(width=>200,height=>200);
rlm@78 7 #or
rlm@78 8 my $svg= SVG->new(width=>200,height=>200);
rlm@78 9
rlm@78 10 # use explicit element constructor to generate a group element
rlm@78 11 my $y=$svg->group(
rlm@78 12 id => 'group_y',
rlm@78 13 style => { stroke=>'red', fill=>'green' }
rlm@78 14 );
rlm@78 15
rlm@78 16 # add a circle to the group
rlm@78 17 $y->circle(cx=>100, cy=>100, r=>50, id=>'circle_in_group_y');
rlm@78 18
rlm@78 19 # or, use the generic 'tag' method to generate a group element by name
rlm@78 20 my $z=$svg->tag('g',
rlm@78 21 id => 'group_z',
rlm@78 22 style => {
rlm@78 23 stroke => 'rgb(100,200,50)',
rlm@78 24 fill => 'rgb(10,100,150)'
rlm@78 25 }
rlm@78 26 );
rlm@78 27
rlm@78 28 # create and add a circle using the generic 'tag' method
rlm@78 29 $z->tag('circle', cx=>50, cy=>50, r=>100, id=>'circle_in_group_z');
rlm@78 30
rlm@78 31 # create an anchor on a rectangle within a group within the group z
rlm@78 32 my $k = $z->anchor(
rlm@78 33 id => 'anchor_k',
rlm@78 34 -href => 'http://test.hackmare.com/',
rlm@78 35 target => 'new_window_0'
rlm@78 36 )->rectangle(
rlm@78 37 x => 20, y => 50,
rlm@78 38 width => 20, height => 30,
rlm@78 39 rx => 10, ry => 5,
rlm@78 40 id => 'rect_k_in_anchor_k_in_group_z'
rlm@78 41 );
rlm@78 42
rlm@78 43 # now render the SVG object, implicitly use svg namespace
rlm@78 44 print $svg->xmlify;
rlm@78 45
rlm@78 46 # or render a child node of the SVG object without rendering the entire object
rlm@78 47 print $k->xmlify; #renders the anchor $k above containing a rectangle, but does not
rlm@78 48 #render any of the ancestor nodes of $k
rlm@78 49
rlm@78 50
rlm@78 51 # or, explicitly use svg namespace and generate a document with its own DTD
rlm@78 52 print $svg->xmlify(-namespace=>'svg');
rlm@78 53
rlm@78 54 # or, explicitly use svg namespace and generate an in-line docunent
rlm@78 55 print $svg->xmlify(
rlm@78 56 -namespace => "svg",
rlm@78 57 -pubid => "-//W3C//DTD SVG 1.0//EN",
rlm@78 58 -inline => 1
rlm@78 59 );