NAME

    Graphics::Raylib - Perlish wrapper for Raylib videogame library

VERSION

    version 0.018

SYNOPSIS

        use Graphics::Raylib;
        use Graphics::Raylib::Text;
        use Graphics::Raylib::Color ':all';
    
        my $g = Graphics::Raylib->window(120,20);
        $g->fps(5);
    
        my $text = Graphics::Raylib::Text->new(
            text => 'Hello World!',
            color => DARKGRAY,
            size => 20,
        );
    
        while (!$g->exiting) {
            Graphics::Raylib::draw {
                $g->clear;
    
                $text->draw;
            };
        }

raylib

    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
    <http://www.raylib.com/examples.html> or games
    <http://www.raylib.com/games.html>!

IMPLEMENTATION

    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. Check out the examples/ directory for
    examples on how to do so.

TESTING

    If you want to skip graphical tests when installing, define
    NO_GRAPHICAL_TEST in the environment. These tests are also skipped
    automatically if no graphic device is available.

AUTOMATIC IMPORT

    use Graphics::Raylib '+family'; can be used as a shorthand for

        use Graphics::Raylib::Color ':all';
        use Graphics::Raylib::Shape;
        use Graphics::Raylib::Texture;
        use Graphics::Raylib::Text;
        use Graphics::Raylib::Mouse;
        use Graphics::Raylib::Keyboard ':all';

METHODS/SUBS AND ARGUMENTS

    window($width, $height, [$title = $0])

      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.

      If no graphic device is available it returns an undef value.

    fps($fps)

      If $fps is supplied, sets the frame rate to that value. Returns the
      frame rate in both cases.

    clear($color)

      Clears the background to $color. $color defaults to
      Graphics::Raylib::Color::RAYWHITE.

    exiting()

      Returns true if user attempted exit.

    draw($coderef)

      Begins drawing, calls $coderef->() and ends drawing. See examples.

    draw3D($coderef)

      Begins 3D drawing, calls $coderef-()> and ends drawing. See examples.

EXAMPLES

    Conway's Game of Life

          my $HZ = 120;
          my $SIZE = 160;
          ###########
      
          my $CELL_SIZE = 3;
      
          use Graphics::Raylib '+family'; # one use to rule them all
          # Alternatively
          use Graphics::Raylib::Color ':all';
          use Graphics::Raylib::Shape;
          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 => RED, size => 20);
      
          my $img = Graphics::Raylib::Texture->new(
              matrix => unpdl($gen),
              fullscreen => 1,
              # color => GOLD # commented-out, we are doing it fancy
          );
      
          my $rainbow = Graphics::Raylib::Color::rainbow(colors => 240);
      
          while (!$g->exiting) {
              $img->matrix = unpdl($gen);
              $img->color = $rainbow->();
              $text->text = "Generation " . ($i++);
      
              $g->clear(BLACK);
      
              Graphics::Raylib::draw {
                  $img->draw;
                  $text->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;
          }

 Result

 More?

    Check out the examples/
    <https://github.com/athreef/Graphics-Raylib/tree/master/examples>
    directory in the distribution or at raylib
    <https://github.com/raysan5/raylib/tree/master/examples>. Also check
    out the games in the repository!

GIT REPOSITORY

    http://github.com/athreef/Graphics-Raylib

SEE ALSO

    http://www.raylib.com

    Graphics::Raylib::Shape

    Graphics::Raylib::XS Alien::raylib

AUTHOR

    Ahmad Fatoum <athreef@cpan.org>, http://a3f.at

COPYRIGHT AND LICENSE

    Copyright (C) 2017-2018 Ahmad Fatoum

    This library is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.

RAYLIB LICENSE

    This is an unofficial wrapper of http://www.raylib.com.

    raylib is Copyright (c) 2013-2016 Ramon Santamaria and available under
    the terms of the zlib/libpng license. Refer to XS/LICENSE.md for full
    terms.

