Munching squares: Difference between revisions

From Rosetta Code
Content added Content deleted
(added ocaml)
m (removed "thumb" attribute from the images because it introduces a CSS float right which doesn't display nicely)
Line 3: Line 3:


=={{header|Mathematica}}==
=={{header|Mathematica}}==

[[File:xorpattern3.png|Mathematica output #1|thumb|200px]]
Output #1:
<lang Mathematica>
<lang Mathematica>
ListDensityPlot[
ListDensityPlot[
Line 12: Line 11:
</lang>
</lang>


Output #1:
[[File:xorpattern4.png|Mathematica output #2|thumb|200px]]

Output #2:
[[File:xorpattern3.png|Mathematica output #1|200px]]

<lang Mathematica>
<lang Mathematica>
ArrayPlot[Array[BitXor, {511, 511}]]
ArrayPlot[Array[BitXor, {511, 511}]]
</lang>
</lang>

Output #2:

[[File:xorpattern4.png|Mathematica output #2|200px]]


=={{header|OCaml}}==
=={{header|OCaml}}==

Revision as of 17:51, 28 November 2011

Munching squares is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

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

Mathematica

<lang Mathematica> ListDensityPlot[

Table[Table[
  FromDigits[BitXor[IntegerDigits[x, 2, 8], IntegerDigits[y, 2, 8]], 
   2], {x, 0, 255}], {y, 0, 255}]]

</lang>

Output #1:

Mathematica output #1

<lang Mathematica> ArrayPlot[Array[BitXor, {511, 511}]] </lang>

Output #2:

Mathematica output #2

OCaml

<lang ocaml>open Graphics

let () =

 open_graph "";
 resize_window 256 256;
 for y = 0 to pred (size_y()) do
   for x = 0 to pred (size_x()) do
     let v = (x lxor y) land 0xFF in
     set_color (rgb v (255 - v) 0);
     plot x y
   done;
 done;
 ignore(read_key())</lang>

Run with:

$ ocaml graphics.cma xor_pattern.ml