I've been the Spritz sdk in my ios apps, and I love it. For funsies I wanted to see how much less code a mathematica version would take! Using dynamic I get a nice result, shown below in code.
However, I'm not so sure about the accuracy of the reading rate that I display (in words per minutes). How can I check and see if it is displaying an accurate frame rate with my usage of Dynamic[]? Also, What should the upper limit of the rate in the slider be calculated?
aliceInWonderlandWords = StringSplit@ExampleData[{"Text","AliceInWonderland"}];
optimalRecognitionPoint[w_String] := With[{len = StringLength[w]},
Which[len==1||len==2, len, len==3, 2, True, Round[len*0.49,1]]
]
$maxLength = 20;
flashWord[word_String, maxWordLength_:20] := Module[
{redIndex = optimalRecognitionPoint[word], leftPart, rightPart, chars, row},
leftPart = $maxLength/2-redIndex;
rightPart = $maxLength-(leftPart+StringLength[word]);
chars = MapIndexed[Style[#1, If[First[#2]==redIndex, Red, Black]]&, Characters@word];
row = ArrayPad[chars, {leftPart, rightPart}," "];
Style[
Grid[ArrayPad[{row},{1,1},Table["",{Length[row]}]],
Dividers -> {(maxWordLength/2+1) -> True,False}, Spacings->{.2,.5}],
FontFamily -> "Monaco", FontSize -> 24 (* This must be a fixed width font! *)
]
];
spritzDemo[words_] := DynamicModule[
{rate = 500/60},
Panel @ Column[{
Row[{Slider[Dynamic[rate], {500/60, 2000/60}, Appearance-> Large,ImageSize->140],
" ", Dynamic[IntegerPart[rate*60]], " words per minute"}," "],
Animate[flashWord[words[[progress]]], {progress, 1, Length[words],1}, AnimationRate -> Dynamic@rate]
}]
]
spritzDemo[aliceInWonderlandWords]
And for bonus points - how could I shorten the code and put the controls into a single panel?
ArrayPad::mlens: Padding amount {10-orp[here ],6+orp[here should be an integer, pair of integers, or list of pairs of integers.
screen shot !Mathematica graphics $\endgroup$orp
should beoptimalRecognitionPoint
? $\endgroup$optimalRecognitionPoint
toorp
you get a working animation. $\endgroup$