Mathematica Asked by Putterboy on February 24, 2021
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
]
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
Correct answer by kglr on February 24, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP