Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 5 down vote accepted
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

share|improve this answer
    
Thanks so much for your generous help. –  Putterboy Jul 24 at 9:11
    
@user16069, you are most welcome. BTW, just noticed that your profile shows 0 votes and 0 acceptances; I think you should consider voting for questions/answers that you find useful :) –  kguler Jul 24 at 9:28
    
Sorry, I'm still new here, I don't know I can upvote somebody. –  Putterboy Jul 24 at 9:46
    
@user16069 You certainly can! Click on the up arrow next to a post that you like :) –  rm -rf Jul 24 at 12:56
    
Yes,thanks, I know how to do it now. –  Putterboy Jul 25 at 2:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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