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 like ubpdqn's last edition & Mr Wizard's refactoring to my last question very much. I inserted two Reverse just to make the diagrams and the strings match in order.

fun[str : {__String}] := 
 Module[{fs, n, timd}, 
  fs = Riffle[#, #]~Append~Last[#] & /@ ToExpression@Characters@str;
  n = Length@First@fs;
  timd = Reverse@fs~Append~PadLeft[{0}, n, {0, 1}];

  ListLinePlot[MapIndexed[#1 + 2 First@#2 - 2 &, timd], 
   InterpolationOrder -> 0, Frame -> True, 
   FrameTicks -> {Thread[{Range[1.5, n - 1.5, 2], Range[n/2]}], 
     Thread[{Range[0.5, 2 Length@timd, 2], 
       Join[Reverse@str, {"clock"}]}], None, None}, 
   PlotRange -> {{0, n + 1}, Automatic}]]

enter image description here

And here, I managed to make the input strings rotate dynamically with the following code, the problem is I failed to make the timing display rotates with the strings as well. Pls help.

str2 = {"11000011", "00000011", "11100111"};
Dynamic[
 Refresh[str2 = {StringJoin[RotateRight[Characters[str2[[1]] ]]], 
    StringJoin[RotateRight[Characters[str2[[2]] ]]],
    StringJoin[RotateRight[Characters[str2[[3]] ]]]
    };
  Column[{str2[[1]], str2[[2]], str2[[3]]}], UpdateInterval -> 1
  ],
 TrackedSymbols -> {}
 ]
share|improve this question
    
You may like StringRotateRight if you have V9 or later :) –  kguler Jul 19 at 1:23

1 Answer 1

up vote 2 down vote accepted

First, a small change in your function fun to allow options:

funB[str : {__String}, opts : OptionsPattern[]] := 
  Module[{fs, n, timd}, 
     fs = Riffle[#, #]~Append~Last[#] & /@ ToExpression@Characters@str;
     n = Length@First@fs;
     timd = Reverse@fs~Append~PadLeft[{0}, n, {0, 1}];
     ListLinePlot[MapIndexed[#1 + 2 First@#2 - 2 &, timd], 
                 InterpolationOrder -> 0, Frame -> True, 
                 FrameTicks -> {Thread[{Range[1.5, n - 1.5, 2], Range[n/2]}], 
                                Thread[{Range[0.5, 2 Length@timd, 2], 
                                Join[Reverse@str, {"clock"}]}], None, None}, 
     PlotRange -> {{0, n + 1}, Automatic}, opts]]

Then, just insert funB[str2] inside Refresh:

  str2 = {"11000011", "00000011", "11100111"};

  Dynamic[Refresh[str2 = StringRotateRight /@ str2;
          Row[{Column[str2] // Style[#, 36] &, funB[str2, ImageSize -> 500]}, 
               Alignment -> Center], 
         UpdateInterval -> 1], TrackedSymbols -> {}]

enter image description here

Update: You can also use Clock and use the third argument of Clock to control the number of repetitions:

 Dynamic[{Clock[{1, 1}, 2, 1]; str2 = StringRotateRight /@ str2;
     Row[{Column[str2] // Style[#, 36] &, funB[str2, ImageSize -> 500]}, 
     Alignment -> Center]}, TrackedSymbols -> {}]
share|improve this answer
    
Is there a way to stop the program? Mousedown can pause the program, "Alt+." & "Alt+," can't stop the execution. –  Putterboy Jul 19 at 7:20
    
You can toggle Dynamic Updating Enabled in the Evaluation menu. –  kguler Jul 19 at 23:27
    
Thanks a lot for your help. –  Putterboy Jul 20 at 3:10
    
@user16069, my pleasure. Welcome to mma.se. –  kguler Jul 20 at 3:34

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.