2015-11-18 06:14:39 +00:00
|
|
|
class Pixel { has UInt ($.R, $.G, $.B) }
|
2013-04-10 22:43:41 -07:00
|
|
|
class Bitmap {
|
2015-11-18 06:14:39 +00:00
|
|
|
has UInt ($.width, $.height);
|
|
|
|
|
has Pixel @!data;
|
2013-04-10 22:43:41 -07:00
|
|
|
|
2015-02-20 00:35:01 -05:00
|
|
|
method fill(Pixel $p) {
|
2015-11-18 06:14:39 +00:00
|
|
|
@!data = $p.clone xx ($!width*$!height)
|
2015-02-20 00:35:01 -05:00
|
|
|
}
|
|
|
|
|
method pixel(
|
2015-11-18 06:14:39 +00:00
|
|
|
$i where ^$!width,
|
|
|
|
|
$j where ^$!height
|
2015-02-20 00:35:01 -05:00
|
|
|
--> Pixel
|
2018-06-22 20:57:24 +00:00
|
|
|
) is rw { @!data[$i + $j * $!width] }
|
2015-02-20 00:35:01 -05:00
|
|
|
|
|
|
|
|
method set-pixel ($i, $j, Pixel $p) {
|
|
|
|
|
self.pixel($i, $j) = $p.clone;
|
|
|
|
|
}
|
|
|
|
|
method get-pixel ($i, $j) returns Pixel {
|
|
|
|
|
self.pixel($i, $j);
|
|
|
|
|
}
|
2013-04-10 22:43:41 -07: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;
|