Bitmap/Midpoint circle algorithm: Difference between revisions
m
→{{header|Perl 6}}: update, add classes from Bitmap task to make runnable example
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: update, add classes from Bitmap task to make runnable example) |
|||
Line 1,374:
=={{header|Perl 6}}==
{{trans|C}}
We'll augment the Pixel and Bitmap classes from the [[Bitmap#Perl_6|Bitmap]] task.
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(
$i where ^$!width,
$j where ^$!height
--> Pixel
) is rw { @!data[$i + $j * $!width] }
method set-pixel ($i, $j, Pixel $p) {
self.pixel($i, $j) = $p.clone;
}
method get-pixel ($i, $j) returns Pixel {
self.pixel($i, $j);
}
}
▲<lang perl6>use MONKEY_TYPING;
augment class Pixel { method Str { "$.R $.G $.B" } }
augment class Bitmap {
|