NAME
Graphics::Raylib::Shape - Collection of drawable shapes
VERSION
version 0.003
SYNOPSIS
use Graphics::Raylib::Pixel;
use Graphics::Raylib::Circle;
use Graphics::Raylib::Rectangle;
use Graphics::Raylib::Triangle;
use Graphics::Raylib::Poly;
# example
my $rect = Graphics::Raylib::Rectangle(
pos => [0,0],
size => [10,10],
color => Graphics::Raylib::Rectange::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( pos => [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->{pos} = [$i * $block_size, 0]; }
- pixel( pos => [$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( pos => [$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, width => $screen_width, height => $screen_height, color => $color )
-
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 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. Return
undef
, for omitting the element.Example:
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(10); my $i = 0; while (!$g->exiting) { my $bitmap = Graphics::Raylib::Shape->bitmap( matrix => unpdl($gen), color => Graphics::Raylib::Color::YELLOW; ); Graphics::Raylib::draw { $g->clear(Graphics::Raylib::Color::BLACK); $bitmap->draw; }; # now do some operations on $pdl, to get next iteration }
See the game of life example at Graphics::Raylib (or
t/10-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.