line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
2671
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
2
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
43
|
|
3
|
|
|
|
|
|
|
package Graphics::Raylib::Shape; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Collection of drawable shapes |
6
|
|
|
|
|
|
|
our $VERSION = '0.002'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
3
|
use List::Util qw(min max); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
83
|
|
9
|
1
|
|
|
1
|
|
159
|
use Graphics::Raylib::XS qw(:all); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=pod |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=encoding utf8 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Graphics::Raylib::Shape - Collection of drawable shapes |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use Graphics::Raylib::Pixel; |
23
|
|
|
|
|
|
|
use Graphics::Raylib::Circle; |
24
|
|
|
|
|
|
|
use Graphics::Raylib::Rectangle; |
25
|
|
|
|
|
|
|
use Graphics::Raylib::Triangle; |
26
|
|
|
|
|
|
|
use Graphics::Raylib::Poly; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# example |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $rect = Graphics::Raylib::Rectangle( |
31
|
|
|
|
|
|
|
pos => [0,0], |
32
|
|
|
|
|
|
|
size => [10,10], |
33
|
|
|
|
|
|
|
color => Graphics::Raylib::Rectange::MAROON, |
34
|
|
|
|
|
|
|
)->draw; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 DESCRIPTION |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Basic geometric shapes that can be drawn while in a C block. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Coordinates and width/height pairs are represented as array-refs to 2 elements |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 METHODS AND ARGUMENTS |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=over 4 |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=item draw() |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Call this on any of the following shapes while in a C block in order to draw the shape. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Wrap-around progress bar example: |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
use Graphics::Raylib; |
53
|
|
|
|
|
|
|
use Graphics::Raylib::Shape; |
54
|
|
|
|
|
|
|
use Graphics::Raylib::Color; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $block_size = 50; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $g = Graphics::Raylib->window($block_size*10, $block_size, "Test"); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$g->fps(5); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $rect = Graphics::Raylib::Shape->rectangle( |
63
|
|
|
|
|
|
|
pos => [1,0], size => [$block_size, $block_size], |
64
|
|
|
|
|
|
|
color => Graphics::Raylib::Color::DARKGREEN |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $i = 0; |
68
|
|
|
|
|
|
|
while (!$g->exiting) { |
69
|
|
|
|
|
|
|
Graphics::Raylib::draw { |
70
|
|
|
|
|
|
|
$g->clear; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$rect->draw; |
73
|
|
|
|
|
|
|
}; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
$i %= 10; |
76
|
|
|
|
|
|
|
$rect->{pos} = [$i * $block_size, 0]; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item pixel( pos => [$x, $y], color => $color ) |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Prepares a single pixel for drawing. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
{ |
88
|
|
|
|
|
|
|
package Graphics::Raylib::Shape::Pixel; |
89
|
|
|
|
|
|
|
use Graphics::Raylib::XS qw(DrawPixel); |
90
|
|
|
|
|
|
|
sub draw { DrawPixel(@{$_[0]->{pos}}, $_[0]->{color} ) } |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
sub pixel { |
93
|
|
|
|
|
|
|
my $class = shift; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $self = { @_ }; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
bless $self, 'Graphics::Raylib::Shape::Pixel'; |
98
|
|
|
|
|
|
|
return $self; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item line( start => [$x, $y], end => [$x, $y], color => $color ) |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Prepares a line for drawing. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
{ |
109
|
|
|
|
|
|
|
package Graphics::Raylib::Shape::Line; |
110
|
|
|
|
|
|
|
use Graphics::Raylib::XS qw(DrawLine); |
111
|
|
|
|
|
|
|
sub draw { DrawLine(@{$_[0]->{start}}, @{$_[0]->{end}}, $_[0]->{color} ) } |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
sub line { |
114
|
|
|
|
|
|
|
my $class = shift; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $self = { @_ }; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
bless $self, 'Graphics::Raylib::Shape::Line'; |
119
|
|
|
|
|
|
|
return $self; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item circle( center => [$x, $y], radius => $r, color => $color ) |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Prepares a circle for drawing. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
{ |
132
|
|
|
|
|
|
|
package Graphics::Raylib::Shape::Circle; |
133
|
|
|
|
|
|
|
use Graphics::Raylib::XS qw(DrawCircle); |
134
|
|
|
|
|
|
|
sub draw { DrawCircle( @{$_[0]->{center}}, $_[0]->{radius}, $_[0]->{color} ) } |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
sub circle { |
137
|
|
|
|
|
|
|
my $class = shift; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
my $self = { @_ }; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
bless $self, 'Graphics::Raylib::Shape::Circle'; |
142
|
|
|
|
|
|
|
return $self; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item rectangle( pos => [$x, $y], size => [$width, $height], color => $color ) |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
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. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
{ |
153
|
|
|
|
|
|
|
package Graphics::Raylib::Shape::Rectangle; |
154
|
|
|
|
|
|
|
use Graphics::Raylib::XS qw(DrawRectangle DrawRectangleGradient); |
155
|
|
|
|
|
|
|
sub draw { |
156
|
|
|
|
|
|
|
if (ref($_[0]->{color}) ne 'ARRAY') { |
157
|
|
|
|
|
|
|
DrawRectangle( @{$_[0]->{pos}}, @{$_[0]->{size}}, $_[0]->{color} ) |
158
|
|
|
|
|
|
|
} else { |
159
|
|
|
|
|
|
|
DrawRectangleGradient( @{$_[0]->{pos}}, @{$_[0]->{size}}, @{$_[0]->{color}} ) |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub rectangle { |
165
|
|
|
|
|
|
|
my $class = shift; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
my $self = { @_ }; |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
bless $self, 'Graphics::Raylib::Shape::Rectangle'; |
170
|
|
|
|
|
|
|
return $self; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item triangle( vertices => [ [$x1,$y1], [$x2,$y2], [$x3,$y3] ], color => $color ) |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Prepares a triangle for drawing. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=cut |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
{ |
181
|
|
|
|
|
|
|
package Graphics::Raylib::Shape::Triangle; |
182
|
|
|
|
|
|
|
use Graphics::Raylib::XS qw(DrawTriangle); |
183
|
|
|
|
|
|
|
sub draw { |
184
|
|
|
|
|
|
|
my @v = @{$_[0]->{vertices}}; |
185
|
|
|
|
|
|
|
DrawTriangle( @{$v[0]}, @{$v[1]}, @{$v[2]}, $_[0]->{color} ); |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub triangle { |
190
|
|
|
|
|
|
|
my $class = shift; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
my $self = { @_ }; |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
bless $self, 'Graphics::Raylib::Shape::Triangle'; |
195
|
|
|
|
|
|
|
return $self; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
{ |
199
|
|
|
|
|
|
|
package Graphics::Raylib::Shape::Polygon; |
200
|
|
|
|
|
|
|
# TODO: missing |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item bitmap( matrix => $AoA, width => $screen_width, height => $screen_height, color => $color ) |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Prepares a matrix for printing. C<$AoA> is an array of arrays ref. C<$screen_width> and C<$screenheight> are the size of the area on which the Matrix should be drawn. It defaults to the screen size. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
if C<$color> is a C, it will be used to color all positive $AoA elements. The space occupied by negative and zero elements stays at background color. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
if C<$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 C, for omitting the element. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Example: |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
use PDL; |
214
|
|
|
|
|
|
|
use PDL::Matrix; |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
my $pdl = mpdl [ |
217
|
|
|
|
|
|
|
[0, 1, 1, 1, 0], |
218
|
|
|
|
|
|
|
[1, 0, 0, 0, 0], |
219
|
|
|
|
|
|
|
[0, 1, 1, 1 ,0], |
220
|
|
|
|
|
|
|
[0, 0, 0, 0 ,1], |
221
|
|
|
|
|
|
|
[0, 1, 1, 1 ,0], |
222
|
|
|
|
|
|
|
]; |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
my $g = Graphics::Raylib->window(240, 240); |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
$g->fps(10); |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
my $i = 0; |
229
|
|
|
|
|
|
|
while (!$g->exiting) |
230
|
|
|
|
|
|
|
{ |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
my $bitmap = Graphics::Raylib::Shape->bitmap( |
233
|
|
|
|
|
|
|
matrix => unpdl($gen), |
234
|
|
|
|
|
|
|
color => Graphics::Raylib::Color::YELLOW; |
235
|
|
|
|
|
|
|
); |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
Graphics::Raylib::draw { |
238
|
|
|
|
|
|
|
$g->clear(Graphics::Raylib::Color::BLACK); |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
$bitmap->draw; |
241
|
|
|
|
|
|
|
}; |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
# now do some operations on $pdl, to get next iteration |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
See the game of life example at L for a more complete example. |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=cut |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
{ |
253
|
|
|
|
|
|
|
package Graphics::Raylib::Shape::Bitmap; |
254
|
|
|
|
|
|
|
sub draw { |
255
|
|
|
|
|
|
|
my $self = shift; |
256
|
|
|
|
|
|
|
my $matrix = $self->{matrix}; |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
for my $i ( 0 .. $#$matrix ) { |
259
|
|
|
|
|
|
|
for my $j ( 0 .. $#{ $matrix->[$i] } ) { |
260
|
|
|
|
|
|
|
my $color = $self->{color}($matrix->[$i][$j]); |
261
|
|
|
|
|
|
|
Graphics::Raylib::Shape->rectangle( |
262
|
|
|
|
|
|
|
pos => [$j*$self->{width}, $i*$self->{height}], |
263
|
|
|
|
|
|
|
size => [$self->{width}, $self->{height}], |
264
|
|
|
|
|
|
|
color => $color, |
265
|
|
|
|
|
|
|
)->draw if defined $color; |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
sub bitmap { |
273
|
|
|
|
|
|
|
my $class = shift; |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
my $self = { @_ }; |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
unless (defined $self->{height} && defined $self->{width}) { |
278
|
|
|
|
|
|
|
my $maxlen = max map { scalar @$_ } @{$self->{matrix}}; |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
# cell sizes |
281
|
|
|
|
|
|
|
$self->{width} = GetScreenWidth() / ($maxlen-1); |
282
|
|
|
|
|
|
|
$self->{height} = GetScreenHeight() / $#{$self->{matrix}}; |
283
|
|
|
|
|
|
|
} |
284
|
|
|
|
|
|
|
my $color = $self->{color}; |
285
|
|
|
|
|
|
|
$self->{color} = sub { pop > 0 ? $color : undef } |
286
|
|
|
|
|
|
|
unless ref($color) eq 'CODE'; |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
bless $self, 'Graphics::Raylib::Shape::Bitmap'; |
290
|
|
|
|
|
|
|
return $self; |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
1; |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=back |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=head1 GIT REPOSITORY |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
L |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=head1 SEE ALSO |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
L L |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=head1 AUTHOR |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
Ahmad Fatoum C<< >>, L |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
Copyright (C) 2017 Ahmad Fatoum |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
314
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
=cut |