Death Star: Difference between revisions

m
→‎{{header|Perl 6}}: GLR updates, minor tweaks, added works with
m (→‎{{header|Perl 6}}: GLR updates, minor tweaks, added works with)
Line 765:
=={{header|Perl 6}}==
{{trans|C}}Reimplemented to output a .pgm image.
{{works with|Rakudo|2015.09}}
[[File:Deathstar-perl6.png|thumb]]
<lang perl6>class sphere {
Line 801 ⟶ 802:
$out.say("P5\n$x $y\n$depth"); # .pgm header
say 'Calculating row:';
$out.printwrite( Blob.new( draw_ds(3, .15)».chrs ) );
$out.close;
}
Line 809 ⟶ 810:
my $bs = "\b" x 8;
for ($pos.cy - $pos.r) .. ($pos.cy + $pos.r) -> $y {
noteprint $bs, $y, ' '; # monitor progress
for ($pos.cx - $pos.r) .. ($pos.cx + $pos.r) -> $x {
# black if we don't hit positive sphere, ignore negative sphere
Line 837 ⟶ 838:
 
# normalize a vector
sub normalize (@vec) { return @vec »/» ([+] @vec Z»*« @vec).sqrt }
 
# dot product of two vectors
sub dot (@x, @y) { return -([+] @x Z»*« @y) max 0 }
 
# are the coordinates within the radius of the sphere?
10,333

edits