langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
37
Task/Bitmap/Perl-6/bitmap.pl6
Normal file
37
Task/Bitmap/Perl-6/bitmap.pl6
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
class Pixel {
|
||||
has Int $.R;
|
||||
has Int $.G;
|
||||
has Int $.B;
|
||||
}
|
||||
|
||||
class Bitmap {
|
||||
has Pixel @.data;
|
||||
has Int $.width;
|
||||
has Int $.height;
|
||||
|
||||
method fill(Pixel $p) {
|
||||
for ^$.width X ^$.height -> $i, $j {
|
||||
@.data[$i][$j] = $p.clone;
|
||||
}
|
||||
}
|
||||
|
||||
method set-pixel ( $i, $j, Pixel $value) {
|
||||
fail unless 0 <= $i <= $.width && 0 <= $j <= $.height;
|
||||
@.data[$i][$j] = $value;
|
||||
}
|
||||
|
||||
method get-pixel ($i, $j) {
|
||||
fail unless 0 <= $i <= $.width && 0 <= $j <= $.height;
|
||||
@.data[$i][$j];
|
||||
}
|
||||
}
|
||||
|
||||
# Usage:
|
||||
|
||||
my Bitmap $b = Bitmap.new( width => 10, height => 10);
|
||||
|
||||
$b.fill( Pixel.new( R => 0, G => 0, B => 200) );
|
||||
|
||||
$b.set-pixel( 7, 5, Pixel.new( R => 100, G => 200, B => 0) );
|
||||
|
||||
say $b.perl;
|
||||
Loading…
Add table
Add a link
Reference in a new issue