How to resolve the algorithm Munching squares step by step in the Raku programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Munching squares step by step in the Raku programming language

Table of Contents

Problem Statement

Render a graphical pattern where each pixel is colored by the value of 'x xor y' from an arbitrary color table.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Munching squares step by step in the Raku programming language

Source code in the raku programming language

my $ppm = open("munching0.ppm", :w) orelse .die;

$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();


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 orelse .die;

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

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

$PPM.close;


  

You may also check:How to resolve the algorithm Logical operations step by step in the OCaml programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the Prolog programming language
You may also check:How to resolve the algorithm Dinesman's multiple-dwelling problem step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm Strip comments from a string step by step in the sed programming language
You may also check:How to resolve the algorithm I before E except after C step by step in the Draco programming language