Munching squares

Here's one simple way:

my $ppm = open("munching0.ppm", :w) or
  die "Can't create munching.ppm: $!";

$ppm.print(q :to 'EOT');
P3
256 256
255
EOT

for 0 .. 255 -> $row {
    for 0 .. 255 -> $col {
        my $color = $row +^ $col;
        $ppm.print("0 $color 0 ");
    }
    $ppm.say();
}

$ppm.close();

Another way:

my @colors = map -> $r, $g, $b { Buf.new: $r, $g, $b },
        map -> $x { floor ($x/256) ** 3 * 256 },
            (flat (0...255) Z
             (255...0) Z
             flat (0,2...254),(254,252...0));


my $PPM = open "munching1.ppm", :w or die "Can't create munching.ppm: $!";

$PPM.print: qq:to/EOH/;
    P6
    # munching.pgm
    256 256 
    255
    EOH

$PPM.write: @colors[$_] for ^256 X+^ ^256;

$PPM.close;

Perl 6 output