RosettaCodeData/Task/Bitmap/Raku/bitmap.raku

30 lines
655 B
Raku
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
class Pixel { has UInt ($.R, $.G, $.B) }
class Bitmap {
has UInt ($.width, $.height);
has Pixel @!data;
method fill(Pixel $p) {
@!data = $p.clone xx ($!width*$!height)
}
method pixel(
2026-04-30 12:34:36 -04:00
$i where ^$!width,
$j where ^$!height
--> Pixel
2023-07-01 11:58:00 -04:00
) is rw { @!data[$i + $j * $!width] }
method set-pixel ($i, $j, Pixel $p) {
2026-04-30 12:34:36 -04:00
self.pixel($i, $j) = $p.clone;
2023-07-01 11:58:00 -04:00
}
method get-pixel ($i, $j) returns Pixel {
2026-04-30 12:34:36 -04:00
self.pixel($i, $j);
2023-07-01 11:58:00 -04:00
}
}
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;