Death Star: Difference between revisions

→‎{{header|Perl 6}}: better concurrency
(→‎{{header|Perl 6}}: modernize a bit, add concurrency)
(→‎{{header|Perl 6}}: better concurrency)
Line 1,012:
my $depth = 255; # image color depth
 
my $xwidth = my $yheight = 255; # dimensions of generated .pgm; must be odd
 
my $s = ($xwidth - 1)/2; # scaled dimension to build geometry
 
my @light = normalize([ 4, -1, -3 ]);
Line 1,035:
 
sub MAIN ($outfile = 'deathstar-perl6.pgm') {
spurt $outfile, ("P5\n$xwidth $yheight\n$depth\n"); # .pgm header
my $out = open( $outfile, :a, :bin ) or die "$!\n";
say 'Working...';
Line 1,044:
 
sub draw_ds ( $k, $ambient ) {
my @pixels[$height];
 
my @row[$x];
(($pos.cy - $pos.r) .. ($pos.cy + $pos.r)).race.map: -> $y {
my @row[$xwidth];
(($pos.cx - $pos.r) .. ($pos.cx + $pos.r)).race.map: -> $x {
# black if we don't hit positive sphere, ignore negative sphere
if not hit($pos, $x, $y, my $posz) {
Line 1,068 ⟶ 1,069:
@row[$x + $s] = ($intensity * $depth).Int min $depth;
}
@pixels.append:[$y + $s] = @row;
}
flat |@pixels.map: *.list;
}
 
10,333

edits