Perl-Visualize
view release on metacpan or search on metacpan
Visualize.pm view on Meta::CPAN
print <<BOTTLES;
$prev of beer on the wall
$prev of beer on the wall
Take one down dash it to the ground
$number of beer on the wall
BOTTLES
}
This subroutine prints out one verse of the song given the number of
bottles that remain. Next we need some code to produce a picture of a
wall with beer bottles on it. For this we will use, Image::Magick.
Image::Magick is a toolkit for editing a large variety of image
formats programmatically. We will use it to generate our GIF images on
the fly.
sub drawWall {
my($image, $width,$height) = @_;
for my $y ( 0..3 ) {
for my $x ( 0..($width/10) ) {
my $warn = $image->Draw ( primitive=>'Rectangle',
points=>"@{[($x - ($y%2)*.5)*10]},
@{[$height - $y*5]}
Visualize.pm view on Meta::CPAN
techniques for writing quines to embed the source code in the program
itself. We embed most of the code as a string in C<$_>, eval it then
we edit C<$_> so that it is initialized for one less beer bottle.
Finally, we embed the edited C<$_> in a GIF file.
#!/usr/bin/perl
$_=<<'CODE';
use strict;
use Perl::Visualize;
use Image::Magick;
sub printMessage {...}
sub drawWall {...}
sub drawBottle {...}
sub drawBottles {...}
my $width = 600;
my $height = 100;
my $bottles = 5;
my $image = Image::Magick->new(size=>"${width}x$height");
my $warn;
$image->ReadImage('xc:white');
printMessage $bottles;
drawWall($image, $width, $height);
drawBottles($bottles, $image, $width, $height);
$warn = $image->Write('99.gif');
warn $warn if $warn;
examples/99.pl view on Meta::CPAN
#!/usr/bin/perl
$_=<<'CODE';
use strict;
use Perl::Visualize;
use Image::Magick;
sub printMessage {
my($number) = @_;
my($prev) = $number+1;
$number = $number < 1 ? "No bottles"
: $number == 1 ? "1 bottle"
: "$number bottles";
$prev = $prev < 1 ? "No bottles"
: $prev == 1 ? "1 bottle"
: "$prev bottles";
examples/99.pl view on Meta::CPAN
my($bottles, $image, $width,$height) = @_;
for my $bottle_number ( 1..$bottles ) {
my $x = 5+(($width-10)/100) * (($bottle_number * 3) % 100);
drawBottle $image, $x, $height - 20;
}
}
my($width,$height) = (600,100);
my $bottles = 99;
my $image = Image::Magick->new(size=>"${width}x$height");
printMessage $bottles;
$image->ReadImage('xc:white');
drawWall($image, $width, $height);
drawBottles($bottles, $image, $width, $height);
my $warn = $image->Write('99.gif');
warn $warn if $warn;
__END__
( run in 0.339 second using v1.01-cache-2.11-cpan-beeb90c9504 )