line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
828
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
2
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
40
|
|
3
|
|
|
|
|
|
|
package Graphics::Raylib::Color; |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# ABSTRACT: Colors for use with Graphics::Raylib |
6
|
|
|
|
|
|
|
our $VERSION = '0.002'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
157
|
use Graphics::Raylib::XS qw(:all); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=pod |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=encoding utf8 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Graphics::Raylib::Color - Use predefined Raylib colors or define your own |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use Graphics::Raylib::Color; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $color = Graphics::Raylib::Color::BLACK; |
24
|
|
|
|
|
|
|
my $gray = Graphics::Raylib::Color::rgb(127,127,127); |
25
|
|
|
|
|
|
|
my $rainbow = Graphics::Raylib::Color::rainbow(colors => 100); |
26
|
|
|
|
|
|
|
push @colors, $rainbow->cycle for (1..100); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Colors you can pass to raylib. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 IMPLEMENTATION |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
As a color is basically a 32-bit integer (RGBA) in raylib, the constructors rgba and rgb do little more packing it into an integer and blessing it |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 METHODS AND ARGUMENTS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=over 4 |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item rgba($red, $green, $blue, $alpha) |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Constructs a new Graphics::Raylib::Color instance. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub rgba { |
48
|
|
|
|
|
|
|
my $self = \pack("C4", @_); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
bless $self, 'Color'; |
51
|
|
|
|
|
|
|
return $self; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=item rgb($red, $green, $blue) |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Constructs a new Graphics::Raylib::Color instance out of an opaque color. |
57
|
|
|
|
|
|
|
Calls C with C<$alpha = 255>. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub rgb { |
62
|
|
|
|
|
|
|
rgba(@_, 255); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item rgb($red, $green, $blue) |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Constructs a new Graphics::Raylib::Color instance out of an opaque color. |
68
|
|
|
|
|
|
|
Calls C with C<$alpha = 255>. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=back |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 PREDEFINED COLORS |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
use constant LIGHTGRAY => rgb( 200, 200, 200 ); |
75
|
|
|
|
|
|
|
use constant GRAY => rgb( 130, 130, 130 ); |
76
|
|
|
|
|
|
|
use constant DARKGRAY => rgb( 80, 80, 80 ); |
77
|
|
|
|
|
|
|
use constant LIGHTGREY => rgb( 200, 200, 200 ); |
78
|
|
|
|
|
|
|
use constant GREY => rgb( 130, 130, 130 ); |
79
|
|
|
|
|
|
|
use constant DARKGREY => rgb( 80, 80, 80 ); |
80
|
|
|
|
|
|
|
use constant YELLOW => rgb( 253, 249, 0 ); |
81
|
|
|
|
|
|
|
use constant GOLD => rgb( 255, 203, 0 ); |
82
|
|
|
|
|
|
|
use constant ORANGE => rgb( 255, 161, 0 ); |
83
|
|
|
|
|
|
|
use constant PINK => rgb( 255, 109, 194 ); |
84
|
|
|
|
|
|
|
use constant RED => rgb( 230, 41, 55 ); |
85
|
|
|
|
|
|
|
use constant MAROON => rgb( 190, 33, 55 ); |
86
|
|
|
|
|
|
|
use constant GREEN => rgb( 0, 228, 48 ); |
87
|
|
|
|
|
|
|
use constant LIME => rgb( 0, 158, 47 ); |
88
|
|
|
|
|
|
|
use constant DARKGREEN => rgb( 0, 117, 44 ); |
89
|
|
|
|
|
|
|
use constant SKYBLUE => rgb( 102, 191, 255 ); |
90
|
|
|
|
|
|
|
use constant BLUE => rgb( 0, 121, 241 ); |
91
|
|
|
|
|
|
|
use constant DARKBLUE => rgb( 0, 82, 172 ); |
92
|
|
|
|
|
|
|
use constant PURPLE => rgb( 200, 122, 255 ); |
93
|
|
|
|
|
|
|
use constant VIOLET => rgb( 135, 60, 190 ); |
94
|
|
|
|
|
|
|
use constant DARKPURPL => rgb( 112, 31, 126 ); |
95
|
|
|
|
|
|
|
use constant BEIGE => rgb( 211, 176, 131 ); |
96
|
|
|
|
|
|
|
use constant BROWN => rgb( 127, 106, 79 ); |
97
|
|
|
|
|
|
|
use constant DARKBROWN => rgb( 76, 63, 47 ); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
use constant WHITE => rgb( 255, 255, 255 ); |
100
|
|
|
|
|
|
|
use constant BLACK => rgb( 0, 0, 0 ); |
101
|
|
|
|
|
|
|
use constant BLANK => rgba( 0, 0, 0, 0 ); |
102
|
|
|
|
|
|
|
use constant MAGENTA => rgb( 255, 0, 255 ); |
103
|
|
|
|
|
|
|
use constant RAYWHITE => rgb( 245, 245, 245 ); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
use constant LIGHTGRAY => rgb( 200, 200, 200 ); |
108
|
|
|
|
|
|
|
use constant GRAY => rgb( 130, 130, 130 ); |
109
|
|
|
|
|
|
|
use constant DARKGRAY => rgb( 80, 80, 80 ); |
110
|
|
|
|
|
|
|
use constant LIGHTGREY => rgb( 200, 200, 200 ); |
111
|
|
|
|
|
|
|
use constant GREY => rgb( 130, 130, 130 ); |
112
|
|
|
|
|
|
|
use constant DARKGREY => rgb( 80, 80, 80 ); |
113
|
|
|
|
|
|
|
use constant YELLOW => rgb( 253, 249, 0 ); |
114
|
|
|
|
|
|
|
use constant GOLD => rgb( 255, 203, 0 ); |
115
|
|
|
|
|
|
|
use constant ORANGE => rgb( 255, 161, 0 ); |
116
|
|
|
|
|
|
|
use constant PINK => rgb( 255, 109, 194 ); |
117
|
|
|
|
|
|
|
use constant RED => rgb( 230, 41, 55 ); |
118
|
|
|
|
|
|
|
use constant MAROON => rgb( 190, 33, 55 ); |
119
|
|
|
|
|
|
|
use constant GREEN => rgb( 0, 228, 48 ); |
120
|
|
|
|
|
|
|
use constant LIME => rgb( 0, 158, 47 ); |
121
|
|
|
|
|
|
|
use constant DARKGREEN => rgb( 0, 117, 44 ); |
122
|
|
|
|
|
|
|
use constant SKYBLUE => rgb( 102, 191, 255 ); |
123
|
|
|
|
|
|
|
use constant BLUE => rgb( 0, 121, 241 ); |
124
|
|
|
|
|
|
|
use constant DARKBLUE => rgb( 0, 82, 172 ); |
125
|
|
|
|
|
|
|
use constant PURPLE => rgb( 200, 122, 255 ); |
126
|
|
|
|
|
|
|
use constant VIOLET => rgb( 135, 60, 190 ); |
127
|
|
|
|
|
|
|
use constant DARKPURPL => rgb( 112, 31, 126 ); |
128
|
|
|
|
|
|
|
use constant BEIGE => rgb( 211, 176, 131 ); |
129
|
|
|
|
|
|
|
use constant BROWN => rgb( 127, 106, 79 ); |
130
|
|
|
|
|
|
|
use constant DARKBROWN => rgb( 76, 63, 47 ); |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
use constant WHITE => rgb( 255, 255, 255 ); |
133
|
|
|
|
|
|
|
use constant BLACK => rgb( 0, 0, 0 ); |
134
|
|
|
|
|
|
|
use constant BLANK => rgba( 0, 0, 0, 0 ); |
135
|
|
|
|
|
|
|
use constant MAGENTA => rgb( 255, 0, 255 ); |
136
|
|
|
|
|
|
|
use constant RAYWHITE => rgb( 245, 245, 245 ); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=over 4 |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item Rainbow->new(colors => $color_count) |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Creates a new Graphics::Raylib::Color::Rainbow instance. C<$color_count> is the total number of colors before bouncing back. Default is C<7>. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
{ |
147
|
|
|
|
|
|
|
package Graphics::Raylib::Color::Rainbow; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub new { |
150
|
|
|
|
|
|
|
my $class = shift; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
my $self = { |
153
|
|
|
|
|
|
|
cycle => 0, |
154
|
|
|
|
|
|
|
colors => 7, |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
@_ |
157
|
|
|
|
|
|
|
}; |
158
|
|
|
|
|
|
|
$self->{freq} = 5 / $self->{colors}; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
bless $self, $class; |
161
|
|
|
|
|
|
|
return $self; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item Rainbow->cycle() |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Returns the next rainbow Graphics::Raylib::Color in sequence. When C<$color_count> is reached, It oscillates back to zero returning the same colors in reverse. At zero, it is back at normal. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub cycle { |
171
|
|
|
|
|
|
|
my $self = shift; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
my $r = int(sin($self->{freq} * abs($self->{cycle}) + 0) * (127) + 128); |
174
|
|
|
|
|
|
|
my $g = int(sin($self->{freq} * abs($self->{cycle}) + 1) * (127) + 128); |
175
|
|
|
|
|
|
|
my $b = int(sin($self->{freq} * abs($self->{cycle}) + 3) * (127) + 128); |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
$self->{cycle} *= -1 if ++$self->{cycle} == $self->{colors}; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
return Graphics::Raylib::Color::rgb($r, $g, $b); |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
1; |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=back |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 GIT REPOSITORY |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
L |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 SEE ALSO |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
L |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
L |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 AUTHOR |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Ahmad Fatoum C<< >>, L |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Copyright (C) 2017 Ahmad Fatoum |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
206
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=cut |