I managed to make a mod4 addition table.

Grid[Table[Mod[i + j, 4], {i, 0, 3}, {j, 0, 3}]]

What I'd like to do is draw a grid of 16 small blocks, 4 rows, 4 columns, each colored according to a color associated with the number in my table.

I'm sure there might be some duplicated help on this, so please let me know, but I am looking for a very elementary start.

Also, once I have this basic plot, I want to try translation, rotation, and reflection, keeping the original and the transformed in the final image.

Update: Thanks to RomkeBonteko, MatrixPlot provides a first image I need.

enter image description here

Now, I'd like to remove the frame, ticks, edge padding, then reflect it across its right edge so that I now have 4 rows and 8 columns of blocks. Then I'd like to flip this result over its bottom edge to get a final image of 8 rows and 8 columns of blocks.

Then I want to work on translations and rotations of the original 4-by-4 image.

  • 2
    $\begingroup$ For your first question, is MatrixPlot what you need? $\endgroup$ – Romke Bontekoe Apr 16 '16 at 7:41
  • $\begingroup$ @RomkeBontekoe That is not only a good reminder, but I am going to do all of the examples in the documentation for MatrixPlot. I've edited my original question with my MatrixPlot. $\endgroup$ – David Apr 16 '16 at 14:49
reflectedMPF = With[{m = ArrayPad[#, Thread[{0, Dimensions[#]}], "Reversed"]}, 
               MatrixPlot[m, Frame -> False]]&


reflectedMPF@Table[Mod[i + j, 4], {i, 0, 3}, {j, 0, 3}]

Mathematica graphics

reflectedMPF[RandomInteger[100, {5, 10}]]

Mathematica graphics


I think this is what you need for reflection.

reflectBottom[x_] := Join[x, Reverse[x]];
reflectRight[x_] := Transpose@reflectBottom@Transpose[x];

Table[Mod[i + j, 4], {i, 0, 3}, {j, 0, 3}] // 
 MatrixPlot[reflectBottom@reflectRight[#], Frame -> None] &

enter image description here


rotate90[x_] := Transpose@Reverse[x];
rotate90Glue[x_] := Transpose@Join[Transpose[x], Reverse[x]];

MatrixPlot[#, Frame -> None] & /@ {#, reflectBottom[#], 
    reflectRight[#], rotate90[#], rotate90Glue[#]} &@
 Table[Mod[i + 2 j, 7], {i, 0, 3}, {j, 0, 3}]

enter image description here

I changed your pixel function, because the original one was too symmetric, so it was hard to check.

What is your final goal?

  • $\begingroup$ How about rotating the original image 90 degrees using its lower right corner as the pivot point. $\endgroup$ – David Apr 20 '16 at 22:02
  • $\begingroup$ @David See update $\endgroup$ – BlacKow Apr 20 '16 at 22:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.