Bitmap/Midpoint circle algorithm: Difference between revisions
→{{header|Raku}}: fix error, DRY, 'clone' not needed, emphasize parallelism, create output
(added Perl programming solution) |
SqrtNegInf (talk | contribs) (→{{header|Raku}}: fix error, DRY, 'clone' not needed, emphasize parallelism, create output) |
||
Line 2,090:
has Pixel @!data;
method fill(Pixel
@!data =
}
) is rw { @!data[$i + $j * $!width] }▼
method
self.pixel($i, $j) = $p.clone;▼
}
method get-pixel ($i, $j) returns Pixel {▼
}
}
}
augment class Pixel { method Str { "$.R $.G $.B" } }
augment class Bitmap {
method P3 {
join "\n", «P3 "$.width $.height" 255»,
do for ^($.width × $.height) { join ' ', @
}
method raster-circle ( \x0,
my $ddF_x = 0;
my $ddF_y = -2
my
self.set-pixel(
▲ self.set-pixel($x0 - $r, $y0, $value);
while $x < $y {
$x++; $f += 1 + ($
for flat (1,-1) X
self.set-pixel(x0 + i×$
}
▲ $x++;
▲ self.set-pixel($x0 + $y, $y0 + $x, $value);
}
}
}
}</lang>▼
my Bitmap $b = Bitmap.new( width => 32, height => 32);
$b.fill( Pixel.new( R => 0, G => 0, B => 0) );
$b.raster-circle(16, 16, 15, Pixel.new(R=>0, G=>0, B=>100));
=={{Header|OCaml}}==
|