1
$\begingroup$

I would like to produce something like the output of a RulePlot for a CellularAutomaton, but where the output state is an integer instead of a color. I mean something like this, which I made in photoshop:

enter image description here

Is it possible to do this using RulePlot?

$\endgroup$
1
$\begingroup$

You can post-process RulePlot output to add text labels:

ClearAll[addLabels]
addLabels[rp_, labels_] := Module[{l = RotateRight@ labels }, 
  Replace[rp, p: {_EdgeForm, {{GrayLevel[x_], Rectangle[a_, b_]}} }  :>
    {p, If[x < .5, GrayLevel[1], GrayLevel[0]], 
     Text[First[l = RotateLeft[l]], Mean[{a, b}]]}, ∞] ]

Examples:

bf = BooleanFunction[{True, True, True, False, False, False, False, False}] ;
rp = RulePlot[bf, ImageSize -> 700]

enter image description here

SeedRandom[1];
labels = RandomInteger[10, 8] 

{1, 4, 0, 7, 0, 0, 8, 6}

addLabels[rp, labels]

enter image description here

rp2 = RulePlot[CellularAutomaton[{679458, 3}], ImageSize -> 600]

enter image description here

SeedRandom[1]
labels2 = RandomInteger[10, 27]

{1, 4, 0, 7, 0, 0, 8, 6, 0, 4, 1, 8, 5, 1, 1, 1, 3, 2, 10, 1, 6, 0, 2, 6, 4, 5, 4}

addLabels[rp2, labels2] 

enter image description here

$\endgroup$

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.