The SWF::Shape Module
The SWF::Shape object holds a data structure that represents a shape as described in Chapter 8. A shape consists of a series of points, a fill style, and a line style. Example 9-2 uses the methods of the Shape object to draw a logarithmic spiral using the Golden Mean (see http://mathworld.wolfram.com/GoldenRatio.html).
The spiral starts at the origin and the pen moves in a
counterclockwise direction. The direction of the curve is determined
by cycling through the @dx and
@dy arrays; the first segment
should be drawn in the positive x and y directions, the second in the
positive x, negative y directions, etc. The control points are always
on the outside edges of the curve. The result is pictured in Figure 9-3.

#!/usr/bin/perl -w # # Example 9-2. An example using SWF::Shape( ) use strict; use SWF::Shape; SWF::setScale(1.0); my $s = new SWF::Shape( ); # Create a new Shape object $s->setLineStyle(1, 255, 0, 0); my @dx = (1, 1, −1, −1); my @dy = (1, −1, −1, 1); my ($x, $y) = (0, 0); my ($x1, $y1) = (0, 0); my $w = 100; my ($cx, $cy); $s->movePenTo($x, $y); for(my $i=0; $i <= 10; $i++) { $x1 = $x1 + $dx[$i%4] * $w; $y1 = $y1 + $dy[$i%4] * $w; if ($i % 2) { # An odd turn ($cx, $cy) = ($x1, $y); } else { # An even turn ($cx, $cy) = ($x, $y1); } $s->drawCurveTo($cx, $cy, $x1, ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access