Image-Magick-PolyText

 view release on metacpan or  search on metacpan

examples/test.im.pl  view on Meta::CPAN

#!/usr/bin/env perl

use strict;
use warnings;

use Image::Magick;

use List::Maker;

use Math::Derivative 'Derivative1';

use Readonly;

use Time::Elapsed qw(elapsed);

# ------------------------------------------------

Readonly::Scalar my $pi			=> 3.14159;
Readonly::Scalar my $start_time => time;
my($image)						= Image::Magick -> new(size => '800 x 400');
my($result)						= $image -> Read('xc:white');

die $result if $result;

# Generate the (x, y) pairs
# -------------------------
my(@x, $x);
my($y, @y);

# List::Maker can't handle <0 .. 2 * $pi x 0.1>.

my($gap)	= 150; # Vertical gap between curves.
my($s1)		= '';
my($s2)		= '';
my($step)	= $pi;

# Note: The syntax @{[expression]} enables Perl to interpolate
# the result of an expression evaluation into a string.

for $step (<0 .. $step x 0.5>)
{
	$x	= 100 + int(100 * $step);
	$y	=  50 + int(100 * sin($step) );
	$s1	.= "$x $y ";
	$s2	.= "$x @{[$y + $gap]} ";

	push @x, $x;
	push @y, $y;
}

print "X: ", join(', ', @x), ". \n";
print "Y: ", join(', ', @y), ". \n";

# Draw the 2 curves
# -----------------
$result	= $image -> Draw
(
	fill		=> 'None',
	points		=> $s1,
	primitive	=> 'polyline',
	stroke		=> 'Green',
	strokewidth	=> 1,
);

die $result if $result;

$result	= $image -> Draw
(
	fill		=> 'None',
	points		=> $s2,
	primitive	=> 'polyline',
	stroke		=> 'Green',
	strokewidth	=> 1,
);

die $result if $result;

# Draw little rectangles at the (x, y) points
# -------------------------------------------
my($i);



( run in 0.993 second using v1.01-cache-2.11-cpan-39bf76dae61 )