Munching squares: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Added Fōrmulæ)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 166:
}</lang>
{{out}} [[Image:Xor_pattern_c.png|C output|200px]]
 
=={{header|C sharp}}==
<lang csharp>using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
 
class XORPattern
{
static void Main()
{
var size = 0x100;
var black = Color.Black.ToArgb();
var palette = Enumerable.Range(black, size).Select(Color.FromArgb).ToArray();
using (var image = new Bitmap(size, size))
{
for (var x = 0; x < size; x++)
{
for (var y = 0; y < size; y++)
{
image.SetPixel(x, y, palette[x ^ y]);
}
}
image.Save("XORPatternCSharp.png", ImageFormat.Png);
}
}
}</lang>
{{out}}
[[File:XORPatternCSharp.png|XORPatternCSharp.png]]
 
=={{header|C++}}==
Line 332 ⟶ 360:
//--------------------------------------------------------------------------------------------------
</lang>
 
=={{header|C sharp}}==
<lang csharp>using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
 
class XORPattern
{
static void Main()
{
var size = 0x100;
var black = Color.Black.ToArgb();
var palette = Enumerable.Range(black, size).Select(Color.FromArgb).ToArray();
using (var image = new Bitmap(size, size))
{
for (var x = 0; x < size; x++)
{
for (var y = 0; y < size; y++)
{
image.SetPixel(x, y, palette[x ^ y]);
}
}
image.Save("XORPatternCSharp.png", ImageFormat.Png);
}
}
}</lang>
{{out}}
[[File:XORPatternCSharp.png|XORPatternCSharp.png]]
 
=={{header|D}}==
Line 423:
{{out}}
[[File:munching-racket.png]]
 
=={{header|Fōrmulæ}}==
 
In [https://wiki.formulae.org/Munching_squares this] page you can see the solution of this task.
 
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text ([http://wiki.formulae.org/Editing_F%C5%8Drmul%C3%A6_expressions more info]). Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for transportation effects more than visualization and edition.
 
The option to show Fōrmulæ programs and their results is showing images. Unfortunately images cannot be uploaded in Rosetta Code.
 
=={{header|FreeBASIC}}==
Line 454 ⟶ 446:
Sleep
End</lang>
 
=={{header|Fōrmulæ}}==
 
In [https://wiki.formulae.org/Munching_squares this] page you can see the solution of this task.
 
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text ([http://wiki.formulae.org/Editing_F%C5%8Drmul%C3%A6_expressions more info]). Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for transportation effects more than visualization and edition.
 
The option to show Fōrmulæ programs and their results is showing images. Unfortunately images cannot be uploaded in Rosetta Code.
 
=={{header|GLSL}}==
Line 508:
splot [0:255][0:255]-(floor(x)^floor(y))</lang>
{{out}} [[Image:gnuplot_xor.png|Gnuplot output|200px]]
 
=={{header|Haskell}}==
<lang haskell>import qualified Data.ByteString as BY (writeFile, pack)
 
import Data.Bits (xor)
 
main :: IO ()
main =
BY.writeFile
"out.pgm"
(BY.pack
(fmap (fromIntegral . fromEnum) "P5\n256 256\n256\n" ++
[ x `xor` y
| x <- [0 .. 255]
, y <- [0 .. 255] ]))</lang>
 
=={{header|Go}}==
Line 542 ⟶ 527:
f.Close()
}</lang>
 
=={{header|Haskell}}==
<lang haskell>import qualified Data.ByteString as BY (writeFile, pack)
 
import Data.Bits (xor)
 
main :: IO ()
main =
BY.writeFile
"out.pgm"
(BY.pack
(fmap (fromIntegral . fromEnum) "P5\n256 256\n256\n" ++
[ x `xor` y
| x <- [0 .. 255]
, y <- [0 .. 255] ]))</lang>
 
=={{header|Icon}} and {{header|Unicon}}==
Line 671:
 
xor_pattern(384; 384; red; yellow)</lang>
 
 
=={{header|Julia}}==
Line 820 ⟶ 819:
end
</lang>
 
=={{header|Mathematica}}==
<lang Mathematica>ListDensityPlot[
Line 962:
print $img->png</lang>
{{out}} [[File:perl_xor_pattern.png|Perl output|200px]]
 
=={{header|Perl 6}}==
Here's one simple way:
 
<lang perl6>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();
</lang>
 
Another way:
 
<lang perl6>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;</lang>
[[File:perl_6_xor_pattern.png|Perl 6 output|200px]]
 
=={{header|Phix}}==
Line 1,186 ⟶ 1,141:
bm
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
Here's one simple way:
 
<lang perl6>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();
</lang>
 
Another way:
 
<lang perl6>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;</lang>
[[File:perl_6_xor_pattern.png|Perl 6 output|200px]]
 
=={{header|REXX}}==
10,333

edits