I have this text. I need that the first word to change to red in 1 second interval, then the second word, then the third word, until arrive the end of the text.

text = "Experiencie leads us to believe that the motions of physical 
        bodies are controlled by interactions between them and their 
  • 2
    $\begingroup$ You seem to be asking someone just to do all your work for you. If you really have no clue, you should start smaller and learn the language in pieces. StringSplit and Style are good places to start. Eventually you'll need Dynamic, which is a course in itself, as well as maybe Refresh/UpdateInterval. Of course there are a bunch of core language functions you'll need to put it all together. $\endgroup$ – Michael E2 May 19 '18 at 0:30
  • $\begingroup$ I don't know what have you tried, but it's true that you didn't show any code (except the text) in your post, so it makes sense that someone assumes that you have not tried anything. It would be better if you show your existing code and explain where you're stuck at. $\endgroup$ – user202729 May 19 '18 at 4:20
  • $\begingroup$ The "You seem" refers to the form of the question, which is just an expression of need, and how the question makes your intentions appear. Aside from the fact that you wrote the post, my remark is not meant to be personal, and certainly not a comment on your way of being. The form of the question itself shows no work other than providing an example text to process and seems to ask others, by expressing a need, to do all the rest of the work for you. In fact, I did not think it expressed your way of being -- it's not most people's way either, is it? $\endgroup$ – Michael E2 May 19 '18 at 13:26
  • $\begingroup$ I work hard very day to learn Mathematica, but there times code don' t work me.Ok I should have put my work. My code was this : Style[Pause[1]; #1, Red, Pause[2]; #2, Red] &["Hello", "here"] $\endgroup$ – Andres May 19 '18 at 14:09
ss = StringSplit[text];
Dynamic @ Row[MapAt[Style[#, Red] &, ss, {Clock[{1, Length@ss, 1}, Length@ss, 3]}], "  "]

enter image description here

  • $\begingroup$ This was what I really needed, thank you @kglr, your code was very useful and precise. $\endgroup$ – Andres May 19 '18 at 14:18
  • $\begingroup$ I need to exposure a work of the eye human, and with your code finally can do it. I modified your code (apologize for that), changed Row by Column, and the number 3 for 1. $\endgroup$ – Andres May 19 '18 at 14:52
  • $\begingroup$ @Andres, glad it was useful for you. $\endgroup$ – kglr May 19 '18 at 20:58

One possible way. Can be optimized more I suppose.

enter image description here

text = "Experiencie leads us to believe that the motions of physical 
          bodies are controlled by interactions between them and their 

words = StringSplit[text];
i = 1;
 ticks = Not[ticks];
 colored = Table[If[n == i, Style[words[[n]], Red], words[[n]]], {n, 1, 
 i = Mod[i, Length@words];
 Row[Riffle[colored, " "]],

 {{delay, 0.5, "delay"}, 0.1, 3, 0.1, Appearance -> "Labeled"},
 {{ticks, True}, None},
 TrackedSymbols :> {ticks,delay}
  • $\begingroup$ Thanks, @Nasser. $\endgroup$ – Andres May 19 '18 at 2:59

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.