line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
4
|
|
|
4
|
|
53322
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
92
|
|
2
|
4
|
|
|
4
|
|
13
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
166
|
|
3
|
|
|
|
|
|
|
package Graphics::Raylib; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Perlish wrapper for Raylib videogame library |
6
|
|
|
|
|
|
|
our $VERSION = '0.002'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
15
|
use Carp; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
261
|
|
9
|
4
|
|
|
4
|
|
789
|
use Graphics::Raylib::XS qw(:all); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Graphics::Raylib::Color; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=pod |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=encoding utf8 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Graphics::Raylib - Perlish wrapper for Raylib videogame library |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use Graphics::Raylib; |
23
|
|
|
|
|
|
|
use Graphics::Raylib::Text; |
24
|
|
|
|
|
|
|
use Graphics::Raylib::Color; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $g = Graphics::Raylib->window(120,20); |
27
|
|
|
|
|
|
|
$g->fps(5); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $text = Graphics::Raylib::Text->new( |
30
|
|
|
|
|
|
|
text => 'Hello World!', |
31
|
|
|
|
|
|
|
color => Graphics::Raylib::Color::DARKGRAY, |
32
|
|
|
|
|
|
|
size => 20, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
while (!$g->exiting) { |
36
|
|
|
|
|
|
|
Graphics::Raylib::draw { |
37
|
|
|
|
|
|
|
$g->clear; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$text->draw; |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 raylib |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
raylib is highly inspired by Borland BGI graphics lib and by XNA framework. Allegro and SDL have also been analyzed for reference. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
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!. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 IMPLEMENTATION |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
This is a Perlish wrapper around L, but not yet feature complete. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
You can import L for any functions not yet exposed perlishly. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 METHODS/SUBS AND ARGUMENTS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=over 4 |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item window($width, $height, $title) |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Constructs the Graphics::Raylib window. C<$title> is optional and defaults to C<$0>. Resources allocated for the window are freed when the handle returned by C goes out of scope. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub window { |
70
|
|
|
|
|
|
|
my $class = shift; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $self = { |
73
|
|
|
|
|
|
|
width => $_[0], |
74
|
|
|
|
|
|
|
height => $_[1], |
75
|
|
|
|
|
|
|
}; |
76
|
|
|
|
|
|
|
InitWindow($self->{width}, $self->{height}, $_[2] // $0); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
bless $self, $class; |
79
|
|
|
|
|
|
|
return $self; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=item fps($fps) |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
If C<$fps> is supplied, sets the frame rate to that value. Returns the frame rate in both cases. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub fps { |
89
|
|
|
|
|
|
|
shift if $_[0]->isa(__PACKAGE__); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $fps = shift; |
92
|
|
|
|
|
|
|
if (defined $fps) { |
93
|
|
|
|
|
|
|
SetTargetFPS($fps); |
94
|
|
|
|
|
|
|
} else { |
95
|
|
|
|
|
|
|
$fps = GetTargetFPS(); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
$fps |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item clear($color) |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Clears the background to C<$color>. C<$color> defaults to C. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub clear { |
107
|
|
|
|
|
|
|
shift if $_[0]->isa(__PACKAGE__); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
ClearBackground(shift // Graphics::Raylib::Color::RAYWHITE); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item exiting() |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Returns true if user attempted exit. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub exiting { |
120
|
|
|
|
|
|
|
my $self = shift; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
WindowShouldClose(); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
=item draw($coderef) |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Begins drawing, calls C<$coderef->()> and ends drawing. See examples. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub draw(&) { |
131
|
|
|
|
|
|
|
my $block = shift; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
BeginDrawing(); |
134
|
|
|
|
|
|
|
$block->(); |
135
|
|
|
|
|
|
|
EndDrawing(); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub DESTROY { |
139
|
|
|
|
|
|
|
CloseWindow(); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=back |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 EXAMPLES |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=over 4 |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item Conway's Game of Life |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
my $HZ = 60; |
155
|
|
|
|
|
|
|
my $SIZE = 80; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
my $CELL_SIZE = 6; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
use Graphics::Raylib; |
160
|
|
|
|
|
|
|
use Graphics::Raylib::Shape; |
161
|
|
|
|
|
|
|
use Graphics::Raylib::Color; |
162
|
|
|
|
|
|
|
use Graphics::Raylib::Text; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
use PDL; |
165
|
|
|
|
|
|
|
use PDL::Matrix; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub rotations { ($_->rotate(-1), $_, $_->rotate(1)) } |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
my @data; |
170
|
|
|
|
|
|
|
foreach (0..$SIZE) { |
171
|
|
|
|
|
|
|
my @row; |
172
|
|
|
|
|
|
|
push @row, !!int(rand(2)) foreach 0..$SIZE; |
173
|
|
|
|
|
|
|
push @data, \@row; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
my $gen = mpdl \@data; |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
my $g = Graphics::Raylib->window($CELL_SIZE*$SIZE, $CELL_SIZE*$SIZE); |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
$g->fps($HZ); |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
my $text = Graphics::Raylib::Text->new( |
183
|
|
|
|
|
|
|
color => Graphics::Raylib::Color::DARKGRAY, |
184
|
|
|
|
|
|
|
size => 20, |
185
|
|
|
|
|
|
|
); |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
my $rainbow = Graphics::Raylib::Color::Rainbow->new(colors => 240); |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
my $i = 0; |
190
|
|
|
|
|
|
|
while (!$g->exiting) |
191
|
|
|
|
|
|
|
{ |
192
|
|
|
|
|
|
|
my $bitmap = Graphics::Raylib::Shape->bitmap( |
193
|
|
|
|
|
|
|
matrix => unpdl($gen), |
194
|
|
|
|
|
|
|
color => $rainbow->cycle, |
195
|
|
|
|
|
|
|
); |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Graphics::Raylib::draw { |
198
|
|
|
|
|
|
|
$g->clear(Graphics::Raylib::Color::BLACK); |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
$text->{text} = "Generation " . ($i++); |
201
|
|
|
|
|
|
|
$text->draw; |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
$bitmap->draw; |
204
|
|
|
|
|
|
|
}; |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
# replace every cell with a count of neighbours |
208
|
|
|
|
|
|
|
my $neighbourhood = zeroes $gen->dims; |
209
|
|
|
|
|
|
|
$neighbourhood += $_ for map { rotations } map {$_->transpose} |
210
|
|
|
|
|
|
|
map { rotations } $gen->transpose; |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
# next gen are live cells with three neighbours or any with two |
213
|
|
|
|
|
|
|
my $next = $gen & ($neighbourhood == 4) | ($neighbourhood == 3); |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
# procreate |
216
|
|
|
|
|
|
|
$gen = $next; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=back |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 GIT REPOSITORY |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
L |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 SEE ALSO |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
L L |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 AUTHOR |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Ahmad Fatoum C<< >>, L |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Copyright (C) 2017 Ahmad Fatoum |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
238
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=cut |