Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use strict;
- use Graphics::Primitive::Canvas;
- use Geometry::Primitive::Circle;
- use Geometry::Primitive::Polygon;
- use Graphics::Primitive::Paint::Gradient::Linear;
- use Graphics::Primitive::Paint::Gradient::Radial;
- use Graphics::Primitive::Paint::Solid;
- use Graphics::Primitive::Operation::Fill;
- use Graphics::Primitive::Operation::Stroke;
- use Graphics::Color::RGB;
- use Graphics::Primitive::Driver::Cairo;
- my $white = Graphics::Color::RGB->new(red => 1, green => 1, blue => 1, alpha => 1);
- my $black = Graphics::Color::RGB->new(red => 0, green => 0, blue => 0, alpha => 1);
- my $gray = Graphics::Color::RGB->new(red => 0, green => 0, blue => 0, alpha => .25);
- my $darkgray = Graphics::Color::RGB->new(red => 0, green => 0, blue => 0, alpha => .5);
- my $red = Graphics::Color::RGB->new(red => 1, green => 0, blue => 0, alpha => 1);
- my $darkred = Graphics::Color::RGB->new(red => .5, green => 0, blue => 0, alpha => 1);
- my $orange = Graphics::Color::RGB->new(red => 1, green => .54, blue => 0, alpha => 1);
- my $yellow = Graphics::Color::RGB->new(red => 1, green => 1, blue => 0, alpha => 1);
- my $blue = Graphics::Color::RGB->new(red => 0, green => 0, blue => 1, alpha => 1);
- my $otherblue = Graphics::Color::RGB->new( red => .44, green => .63, blue => .76, alpha => 1);
- my $green = Graphics::Color::RGB->new(red => 0, green => 1, blue => 0, alpha => 1);
- my $indigo = Graphics::Color::RGB->new(red => .29, green => 0, blue => .50, alpha => .5);
- my $violet = Graphics::Color::RGB->new(red => .93, green => .50, blue => .93, alpha => .5);
- my $driver = Graphics::Primitive::Driver::Cairo->new(format => 'PNG');
- my $body = Graphics::Primitive::Canvas->new(
- background_color => Graphics::Color::RGB->new(red => 1, green => 1, blue => 1),
- width => 1024,
- height => 768
- );
- $body->move_to(0, 0);
- $body->rectangle(1024, 768);
- my $backgrad = Graphics::Primitive::Paint::Gradient::Linear->new(
- line => Geometry::Primitive::Line->new(
- start => Geometry::Primitive::Point->new(x => 512, y => 0),
- end => Geometry::Primitive::Point->new(x => 512, y => 768),
- ),
- );
- $backgrad->add_stop(0.0, $white);
- $backgrad->add_stop(1, $gray);
- my $backop = Graphics::Primitive::Operation::Fill->new(
- paint => $backgrad
- );
- $body->do($backop);
- $body->path->move_to(100, 300);
- $body->path->ellipse(150, 90, 1);
- my $afillop = Graphics::Primitive::Operation::Fill->new(
- paint => Graphics::Primitive::Paint::Solid->new,
- preserve => 1
- );
- $afillop->paint->color($otherblue);
- my $astrokeop = Graphics::Primitive::Operation::Stroke->new;
- $astrokeop->brush->width(2);
- $astrokeop->brush->color($black);
- $body->do($afillop);
- $body->do($astrokeop);
- $body->path->move_to(500, 500);
- $body->path->arc(300, 0, 6.28, 1);
- my $grad = Graphics::Primitive::Paint::Gradient::Radial->new(
- start => Geometry::Primitive::Circle->new(
- origin => [419, 344],
- radius => 50
- ),
- end => Geometry::Primitive::Circle->new(
- origin => [540, 444],
- radius => 300
- ),
- );
- $grad->add_stop(0.0, $orange);
- $grad->add_stop(.5, $red);
- $grad->add_stop(1, $darkred);
- my $gradop = Graphics::Primitive::Operation::Fill->new(paint => $grad);
- $body->do($gradop);
- $body->path->move_to(725,50);
- $body->path->rectangle(150, 150);
- my $fillop = Graphics::Primitive::Operation::Fill->new(
- paint => Graphics::Primitive::Paint::Solid->new,
- preserve => 1
- );
- $fillop->paint->color($orange);
- my $strokeop = Graphics::Primitive::Operation::Stroke->new;
- $strokeop->brush->width(15);
- $strokeop->brush->color($black);
- $strokeop->brush->line_cap('round');
- $body->do($fillop);
- $body->do($strokeop);
- $body->path->move_to(350, 50);
- $body->arc(50, 0, 3.14, 1);
- $body->close_path;
- my $fillop2 = $fillop->clone;
- $fillop2->paint->color($green);
- my $strokeop2 = $strokeop->clone;
- $strokeop2->brush->width(5);
- $strokeop2->brush->line_join('round');
- $body->do($fillop2);
- $body->do($strokeop2);
- $body->path->move_to(475, 100);
- $body->path->line_to(525, 175);
- $body->path->line_to(575, 50);
- my $strokeop3 = $strokeop->clone;
- $strokeop3->brush->color($blue);
- $strokeop3->brush->line_join('bevel');
- $body->do($strokeop3);
- $body->path->move_to(80, 80);
- $body->path->curve_to(
- [300, 400],
- [400, 100],
- [300, 200]
- );
- $body->do($strokeop);
- my $poly = Geometry::Primitive::Polygon->new;
- $poly->add_point(Geometry::Primitive::Point->new(x => 850, y => 300));
- $poly->add_point(Geometry::Primitive::Point->new(x => 900, y => 300));
- $poly->add_point(Geometry::Primitive::Point->new(x => 900, y => 350));
- $poly->add_point(Geometry::Primitive::Point->new(x => 930, y => 350));
- $poly->add_point(Geometry::Primitive::Point->new(x => 930, y => 370));
- $poly->add_point(Geometry::Primitive::Point->new(x => 900, y => 370));
- $poly->add_point(Geometry::Primitive::Point->new(x => 850, y => 350));
- $body->path->add_primitive($poly);
- my $strokeop4 = $strokeop3->clone;
- $strokeop4->brush->color($indigo);
- $strokeop4->brush->width(8);
- $body->do($strokeop4);
- my $poly = Geometry::Primitive::Polygon->new;
- $poly->add_point(Geometry::Primitive::Point->new(x => 805, y => 370));
- $poly->add_point(Geometry::Primitive::Point->new(x => 900, y => 300));
- $poly->add_point(Geometry::Primitive::Point->new(x => 930, y => 350));
- $body->path->add_primitive($poly);
- my $strokeop5 = $strokeop4->clone;
- $strokeop4->brush->color($violet);
- $body->do($strokeop5);
- $driver->prepare($body);
- $driver->finalize($body);
- $driver->draw($body);
- $driver->write('foo.png');
Add Comment
Please, Sign In to add comment