NAME
Graphics::Raylib::Shape - Collection of drawable shapes
VERSION
version 0.016
SYNOPSIS
use Graphics::Raylib::Shape::Pixel;
use Graphics::Raylib::Shape::Circle;
use Graphics::Raylib::Shape::Rectangle;
use Graphics::Raylib::Shape::Triangle;
use Graphics::Raylib::Shape::Bitmap;
# example
my $rect = Graphics::Raylib::Rectangle(
position => [0,0],
size => [10,10],
color => Graphics::Raylib::Color::MAROON,
)->draw;
DESCRIPTION
Basic geometric shapes that can be drawn while in a Graphics::Raylib::draw
block.
Coordinates and width/height pairs are represented as array-refs to 2 elements
METHODS AND ARGUMENTS
- draw()
-
Call this on any of the following shapes while in a
Graphics::Raylib::draw
block in order to draw the shape.Wrap-around progress bar example:
use Graphics::Raylib; use Graphics::Raylib::Shape; use Graphics::Raylib::Color; my $block_size = 50; my $g = Graphics::Raylib->window($block_size*10, $block_size, "Test"); $g->fps(5); my $rect = Graphics::Raylib::Shape->rectangle( position => [1,0], size => [$block_size, $block_size], color => Graphics::Raylib::Color::DARKGREEN ); my $i = 0; while (!$g->exiting) { Graphics::Raylib::draw { $g->clear; $rect->draw; }; $i %= 10; $rect->{position} = [$i * $block_size, 0]; }
- pixel( position => [$x, $y], color => $color )
-
Prepares a single pixel for drawing.
- line( start => [$x, $y], end => [$x, $y], color => $color )
-
Prepares a line for drawing.
- circle( center => [$x, $y], radius => $r, color => $color )
-
Prepares a circle for drawing.
- rectangle( position => [$x, $y], size => [$width, $height], color => $color )
-
Prepares a solid color rectangle for drawing. if $color is an arrayref of 2 Colors, the fill color will be a gradient of those two.
- triangle( vertices => [ [$x1,$y1], [$x2,$y2], [$x3,$y3] ], color => $color )
-
Prepares a triangle for drawing.
- bitmap( matrix => $AoA, color => $color, [ width => $screen_width, height => $screen_height, transposed => 0, $roatate => 0 ])
-
Creates a texture out of a matrix for printing.
$AoA
is an array of arrays ref.$screen_width
and$screenheight
are the size of the area on which the Matrix should be drawn. It's optional defaults to the screen size.If
$color
is aGraphics::Raylib::Color
, it will be used to color all positive $AoA elements. The space occupied by negative and zero elements stays at background color.if
$color
is a code reference, It will be evaluated for each matrix element, with the element's value as argument. The return type of the code reference will be used for the color. Returnundef
, for omitting the element.transposed =>
determines whether the image should be drawn transposed ( x,y flipped ). It's more effecient than transposing in a separate step.rotate =>
sets an angle (in degrees) for rotation. Rotation origin is the center of the bitmap.Example:
use Graphics::Raylib '+family'; use PDL; use PDL::Matrix; my $pdl = mpdl[ [0, 1, 1, 1, 0], [1, 0, 0, 0, 0], [0, 1, 1, 1 ,0], [0, 0, 0, 0 ,1], [0, 1, 1, 1 ,0], ]; my $g = Graphics::Raylib->window(240, 240); $g->fps(60); my $bitmap = Graphics::Raylib::Shape->bitmap(matrix => unpdl($pdl), color => YELLOW, transposed => 1); while (!$g->exiting) { $bitmap->matrix = unpdl($pdl); $bitmap->rotation -= 1; Graphics::Raylib::draw { $g->clear(BLACK); $bitmap->draw; }; # now do some operations on $pdl, to get next iteration }
See the game of life example at Graphics::Raylib (or
t/30-game-of-life.t
) for a more complete example.
GIT REPOSITORY
http://github.com/athreef/Graphics-Raylib
SEE ALSO
Graphics::Raylib Graphics::Raylib::Color
AUTHOR
Ahmad Fatoum <athreef@cpan.org>
, http://a3f.at
COPYRIGHT AND LICENSE
Copyright (C) 2017 Ahmad Fatoum
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.