#!/usr/bin/perl -w # Example 2-6. Using map() use strict; use GD; my $image = new GD::Image(280,280); # Create a new polygon and add three points my $polygon = new GD::Polygon; $polygon->addPt(140,20); $polygon->addPt(260,260); $polygon->addPt(20,260); # Allocate colors; gray is the background my $gray= $image->colorAllocate(200, 200, 200); my $black = $image->colorAllocate(0,0,0); # Draw the largest triangle first, then map it into progressively # smaller bounding boxes for my $i (0..20) { my ($x1, $y1, $x2, $y2) = $polygon->bounds(); $polygon->map($x1, $y1, $x2, $y2, $x1, $y1, $x2-$i, $y2-$i); $image->polygon($polygon, $black); } # Print the image to STDOUT as a PNG binmode(STDOUT); print $image->png();