Graphics::Raylib - Perlish wrapper for Raylib videogame library
use Graphics::Raylib; use Graphics::Raylib::Text; use Graphics::Raylib::Color; my $g = Graphics::Raylib->window(120,20); $g->fps(5); my $text = Graphics::Raylib::Text->new( text => 'Hello World!', color => Graphics::Raylib::Color::DARKGRAY, size => 20, ); while (!$g->exiting) { Graphics::Raylib::draw { $g->clear; $text->draw; }; }
raylib is highly inspired by Borland BGI graphics lib and by XNA framework. Allegro and SDL have also been analyzed for reference.
NOTE for ADVENTURERS: raylib is a programming library to learn videogames programming; no fancy interface, no visual helpers, no auto-debugging... just coding in the most pure spartan-programmers way. Are you ready to learn? Jump to code examples!.
This is a Perlish wrapper around Graphics::Raylib::XS, but not yet feature complete.
You can import Graphics::Raylib::XS for any functions not yet exposed perlishly.
Constructs the Graphics::Raylib window. $title is optional and defaults to $0. Resources allocated for the window are freed when the handle returned by window goes out of scope.
$title
$0
window
If $fps is supplied, sets the frame rate to that value. Returns the frame rate in both cases.
$fps
Clears the background to $color. $color defaults to Graphics::Raylib::Color::RAYWHITE.
$color
Graphics::Raylib::Color::RAYWHITE
Returns true if user attempted exit.
Begins drawing, calls $coderef-()> and ends drawing. See examples.
$coderef-
my $HZ = 60; my $SIZE = 80; my $CELL_SIZE = 6; use Graphics::Raylib; use Graphics::Raylib::Shape; use Graphics::Raylib::Color; use Graphics::Raylib::Text; use PDL; use PDL::Matrix; sub rotations { ($_->rotate(-1), $_, $_->rotate(1)) } my @data; foreach (0..$SIZE) { my @row; push @row, !!int(rand(2)) foreach 0..$SIZE; push @data, \@row; } my $gen = mpdl \@data; my $g = Graphics::Raylib->window($CELL_SIZE*$SIZE, $CELL_SIZE*$SIZE); $g->fps($HZ); my $text = Graphics::Raylib::Text->new( color => Graphics::Raylib::Color::DARKGRAY, size => 20, ); my $rainbow = Graphics::Raylib::Color::Rainbow->new(colors => 240); my $i = 0; while (!$g->exiting) { my $bitmap = Graphics::Raylib::Shape->bitmap( matrix => unpdl($gen), color => $rainbow->cycle, ); Graphics::Raylib::draw { $g->clear(Graphics::Raylib::Color::BLACK); $text->{text} = "Generation " . ($i++); $text->draw; $bitmap->draw; }; # replace every cell with a count of neighbours my $neighbourhood = zeroes $gen->dims; $neighbourhood += $_ for map { rotations } map {$_->transpose} map { rotations } $gen->transpose; # next gen are live cells with three neighbours or any with two my $next = $gen & ($neighbourhood == 4) | ($neighbourhood == 3); # procreate $gen = $next; }
http://github.com/athreef/Graphics-Raylib
Graphics::Raylib::XS Alien::raylib
Ahmad Fatoum <athreef@cpan.org>, http://a3f.at
<athreef@cpan.org>
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.
To install Graphics::Raylib, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Graphics::Raylib
CPAN shell
perl -MCPAN -e shell install Graphics::Raylib
For more information on module installation, please visit the detailed CPAN module installation guide.