2
$\begingroup$

I intend to implement a three-variables Karnaugh map with the following code. There are two points I failed to figure out. How to remove the outer double-line border? How to change the toggling into "1" and blank instead of black and white? Please help.

labels = {"00", "01", "11", "10"};
frame = Graphics[{
    Line@Table[{{i, 0}, {i, 4}}, {i, 0, 2, 1}],
    Line@Table[{{0, i}, {2, i}}, {i, 0, 4, 1}], 
    Table[Text[
      labels[[3 - i + 1]], {-0.3, i + 0.3}], {i, {0, 1, 3, 2}}], 
    Table[Text[labels[[i + 1]], {i + 0.75, 4.25}], {i, {0, 1, 0, 1}}],
     Line[{{0, 4}, {-0.75, 4.75}}], 
    Text[Style[ "A B" , 12], {-0.5, 4.}], 
    Text[Style["C", 12], {0., 4.5}]}, ImageSize -> {100, 200}];

Manipulate[
  arrX = ConstantArray[0, {2, 4}];
  EventHandler[
  Dynamic[
   mat = Reverse[ Transpose[arrX]] ;
   Show[frame,
    MatrixPlot[
     mat,
     Mesh -> All,
     ImageSize -> {100, 200},
     PlotRangePadding -> 0,
     FrameTicks -> None,
     ColorRules -> {1 -> Black, 0 -> None}]
    ]],
  {
   "MouseClicked" :> (pos = Ceiling[MousePosition["Graphics"]];
     arrX = ReplacePart[arrX, pos -> 1 - arrX[[Sequence @@ pos]]];
     )
   }], 
 AppearanceElements -> None,
 FrameMargins -> 0
 ]

enter image description here

$\endgroup$
0
6
$\begingroup$
Manipulate[arrX = ConstantArray[0, {2, 4}];
    EventHandler[Dynamic[mat = Reverse[Transpose[arrX]];
    Show[frame, 
        MatrixPlot[mat, Mesh -> All, ImageSize -> {100, 200}, 
                   PlotRangePadding -> 0, FrameTicks -> None, 
                    ColorRules -> {1 -> None, 0 -> None}], 
        Epilog -> {MapIndexed[If[#1 == 1, 
                                Text[Style[#1, Bold, 20, Red], #2 - {.5, .5}], 
                                Text[""]] &, 
                              arrX, {2}]}]], 
    {"MouseClicked" :> (pos = Ceiling[MousePosition["Graphics"]];
                    arrX = ReplacePart[arrX, pos -> 1 - arrX[[Sequence @@ pos]]];)}], 
   Paneled -> False, AppearanceElements -> None, 
   FrameMargins -> 0] // Panel

enter image description here

$\endgroup$
4
  • $\begingroup$ Thanks so much for your generous help. $\endgroup$ – Putterboy Jul 24 '14 at 9:11
  • $\begingroup$ Sorry, I'm still new here, I don't know I can upvote somebody. $\endgroup$ – Putterboy Jul 24 '14 at 9:46
  • $\begingroup$ @user16069 You certainly can! Click on the up arrow next to a post that you like :) $\endgroup$ – rm -rf Jul 24 '14 at 12:56
  • $\begingroup$ Yes,thanks, I know how to do it now. $\endgroup$ – Putterboy Jul 25 '14 at 2:08

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.