Subject: | Polygon created visual artifacts |
Change the value in $bezier->curve(), to see other artifacts,
The jpg (see attachment) was created with the following code:
use Image::Imlib2;
use Math::Bezier;
my $width = 300;
my $height = 250;
my $graphwidth = 250;
my $graphheight = 200;
my $grid = 10;
my $dx = ($width - $graphwidth)/2;
my $dy = ($height - $graphheight)/2;
my @control = ( 0, 100, 10, 200, 20, 20, 30, 20, 40, 20, 50, 20, 60, 20, 70, 99, 80, 80, 90, 76, 100, 45, 110, 46, 120, 47, 130, 47, 140, 47, 150, 47, 160, 47, 170, 47, 180, 47, 190, 47, 200, 47, 210, 47, 220, 47, 230, 200, 240, 200);
my $bezier = Math::Bezier->new(\@control);
my $points = $bezier->curve(148);
my $poly = Image::Imlib2::Polygon->new();
$poly->add_point($dx,$graphheight+$dy);
my $lastx;
while (@$points) {
my ($x, $y) = splice(@$points, 0, 2);
$lastx = $x;
# print "$x,$y\n";
$poly->add_point($x+$dx,$height-$y-$dy);
}
$poly->add_point($lastx+$dx,$height-$dy);
$lastx = 0;
my $img = Image::Imlib2->new($width,$height);
$img->has_alpha(1);
$img->set_color(255, 255, 255, 255);
$img->fill_rectangle(0,0,$width,$height);
$img->set_color(0, 0, 0, 127);
$img->set_color(78,130,225,127);
$poly->fill();
$img->draw_polygon($poly, 1);
$img->save('imlib-artifacts.jpg');