ROASP:
| |
An Open-Source contribution from RO IT Systems |
|
Perl SVG Tutorials |
Home | Free Code Samples | SVG Module Documentation | SVG Tutorials | SVG Gallery | Forum & Discussion | SVG Perl Modules | SVG-Perl Articles | External Links | Local Copies of Modules (Win32 & CPAN) | YASB: A Perl SVG Browser |
We are going to first create a new instance of the SVG object. next, first, as in all good programs, we invoke perl witn -w to warn about dangerous coding. We also use strict to force us to declare our variables. Not using strict is a Big Mistake, so we always use strict
#!/usr/bin/perl -w use strict; use SVG;
Next, we create an SVG object and define its height and width.
# create an SVG object my $svg= SVG->new(width=>200,height=>200);
Notice that the constructor [SVG->new()] is called a constructor does not take a list of values but a hash .
# create an SVG object
my %hash;
$hash{width} = 200;
$hash{height} = 200;
my $svg= SVG->new(%hash);
We could even have done this:
# create an SVG object
my $svg= SVG->new('width',200,'height',200);
Remember that '=>' means assign value to. In the SVG module, we are constantly passing a hash as the input to tag-generation methods (A method is a command to the object that owns the method, or in plain English, an action that the SVG module performs). Now that we've invoked the object through it's constructor, let's build a drawing object. We're first going to draw a circle in the center of the object. most of the drawing objects in SVG such as circle, ellipe, rectangle, line, polyline, etc. are called using a method with the same name.
# draw a circle at position (100,100) with ID 'this_circle' $svg->circle(id=>'this_circle',cx=>100,cy=>100,r=>50);
Then we execute the xmlify method (command) which returns the XML text that we just generated.
my $out = $svg->xmlify; print $out
Here is what this program returns:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg height="200" width="200">
<circle id="this_circle" cx="100" cy="100" r="50" />
</svg>
For more information, please send the author an email: Ronan Oger
Click here for the source code, and Click here to see the result.
Previous Tutorial | Tutorial Home | Next Tutorial
August 15-18, Enschede, the Netherlands
At the SVG Open 2005 Conference you will have the opportunity to learn about the SVG standard, how to use it to create effective and compelling Web content, techniques for developing SVG software solutions, and the latest developments from the W3C. You will meet the authors of the SVG specifications and the creators of SVG applications in person, and you will have the opportunity to provide your own input for future development.
You will get a chance to see the newest SVG applications and tools, and you will hear early announcements of upcoming SVG product releases. SVG Open 2005 courses will enlighten you on SVG, XML and related standards, graphic design and Web application design. Courses will be available at both introductory and advanced levels, in order to serve the needs of all conference attendees.
Click on the image below to proceed to the SVG Open website
| SVG Home | © 2002-2005 Ronan Oger | Site Info |