Manipulate -> Pause Play at specific conditions

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
6
down vote

favorite
1












How can I pause play in Manipulate when a condition is met ?
Here is an example:



Manipulate[
Plot[i*Sin[x], x, 0, 10, PlotRange -> 10], i, 1, 10,
AnimationRate -> 3, RefreshRate -> 60, Appearance -> "Open"]


When I press the "Play" Buttom, i increases.
Now, I want the animation to stop automatically, when i reaches a certain value, say i=5.



How can I do that ?



EDIT: Thanks a lot for the great answers.
Would it be possible to implement the following:



  1. One can define points for which play will stop, for instance, at i=2, i=4, and i=8


  2. When i== One of the points -> Then play will stop, if I press the play buttom again, then it will continue to run until the next break point:


Example:



i==2 -> Stop



Manually: Press Play
--> Continues



i==4 -> Stop



Manually: Press Play
--> Continues



etc.







share|improve this question


























    up vote
    6
    down vote

    favorite
    1












    How can I pause play in Manipulate when a condition is met ?
    Here is an example:



    Manipulate[
    Plot[i*Sin[x], x, 0, 10, PlotRange -> 10], i, 1, 10,
    AnimationRate -> 3, RefreshRate -> 60, Appearance -> "Open"]


    When I press the "Play" Buttom, i increases.
    Now, I want the animation to stop automatically, when i reaches a certain value, say i=5.



    How can I do that ?



    EDIT: Thanks a lot for the great answers.
    Would it be possible to implement the following:



    1. One can define points for which play will stop, for instance, at i=2, i=4, and i=8


    2. When i== One of the points -> Then play will stop, if I press the play buttom again, then it will continue to run until the next break point:


    Example:



    i==2 -> Stop



    Manually: Press Play
    --> Continues



    i==4 -> Stop



    Manually: Press Play
    --> Continues



    etc.







    share|improve this question
























      up vote
      6
      down vote

      favorite
      1









      up vote
      6
      down vote

      favorite
      1






      1





      How can I pause play in Manipulate when a condition is met ?
      Here is an example:



      Manipulate[
      Plot[i*Sin[x], x, 0, 10, PlotRange -> 10], i, 1, 10,
      AnimationRate -> 3, RefreshRate -> 60, Appearance -> "Open"]


      When I press the "Play" Buttom, i increases.
      Now, I want the animation to stop automatically, when i reaches a certain value, say i=5.



      How can I do that ?



      EDIT: Thanks a lot for the great answers.
      Would it be possible to implement the following:



      1. One can define points for which play will stop, for instance, at i=2, i=4, and i=8


      2. When i== One of the points -> Then play will stop, if I press the play buttom again, then it will continue to run until the next break point:


      Example:



      i==2 -> Stop



      Manually: Press Play
      --> Continues



      i==4 -> Stop



      Manually: Press Play
      --> Continues



      etc.







      share|improve this question














      How can I pause play in Manipulate when a condition is met ?
      Here is an example:



      Manipulate[
      Plot[i*Sin[x], x, 0, 10, PlotRange -> 10], i, 1, 10,
      AnimationRate -> 3, RefreshRate -> 60, Appearance -> "Open"]


      When I press the "Play" Buttom, i increases.
      Now, I want the animation to stop automatically, when i reaches a certain value, say i=5.



      How can I do that ?



      EDIT: Thanks a lot for the great answers.
      Would it be possible to implement the following:



      1. One can define points for which play will stop, for instance, at i=2, i=4, and i=8


      2. When i== One of the points -> Then play will stop, if I press the play buttom again, then it will continue to run until the next break point:


      Example:



      i==2 -> Stop



      Manually: Press Play
      --> Continues



      i==4 -> Stop



      Manually: Press Play
      --> Continues



      etc.









      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 9 at 6:11

























      asked Aug 8 at 13:36









      james

      563316




      563316




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          Manipulate by default uses Manipulator which doesn't seem to support dynamic values for the AnimationRunning option. However you could use ControlType -> Animator.



          Here's a possible approach where by adding two extra control variables I can stop the animation after i reaches 5 on the first run.



          Manipulate[
          If[initialRun && i >= 5, running = False; initialRun = False];
          Plot[i*Sin[x], x, 0, 10, PlotRange -> 10]
          ,
          initialRun, True, False, ControlType -> None,
          running, True, False, ControlType -> None,
          i, 1, 10, ControlType -> Animator, AnimationRate -> 3,
          RefreshRate -> 60, AnimationRunning -> Dynamic[running]
          ]


          Manipulate with one animation breakpoint



          Note that if the user interacts with the animator before it gets paused by the Manipulate, the pausing will still happen whenever the value of i is 5 or greater first.



          For a version with more than one breakpoint, replace the initialRun boolean with an integer counting how many runs have happened:



          With[breakPoints = 2, 4, 8,
          Manipulate[
          If[runNumber <= Length[breakPoints] && i >= breakPoints[[runNumber]],
          running = False; runNumber++
          ];
          Plot[i*Sin[x], x, 0, 10, PlotRange -> 10]
          ,
          runNumber, 1, ControlType -> None,
          running, True, False, ControlType -> None,
          i, 1, 10, ControlType -> Animator, AnimationRate -> 3, RefreshRate -> 60, AnimationRunning -> Dynamic[running]
          ]
          ]


          Manipulate with several animation breakpoints






          share|improve this answer






















          • +1 Good idea, it seems I am not able to think in this heat. :)
            – Kuba♦
            Aug 8 at 15:42










          • +1, I arrived too late.
            – rhermans
            Aug 8 at 15:44










          • Thank you very much! Great idea, but I would need it to stop when i=5 and then when I push the play button it should continue. Is this possible ?
            – james
            Aug 9 at 5:39










          • Please see the recent edit for more information
            – james
            Aug 9 at 6:12










          • Wow ! This is perfect ! Very well done !! Thank you very much. :))
            – james
            Aug 9 at 8:35

















          up vote
          2
          down vote













          The credit goes to @Gerli, who arrived first. Difference is that mine uses DynamicModule



          DynamicModule[
          s = True,
          Manipulate[
          If[i > 5, s = False, s = True];
          Plot[i*Sin[x], x, 0, 10, PlotRange -> 10],

          i, 1, 10
          , ControlType -> Animator
          , AnimationRunning -> Dynamic[s]
          ]
          ]


          enter image description here






          share|improve this answer






















          • Thank you very much! I would need it to stop when i=5 and then when I push the play button it should continue. Is this possible ?
            – james
            Aug 9 at 5:39










          • Please have a look at the recent edit. Thanks :)
            – james
            Aug 9 at 6:12










          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "387"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f179690%2fmanipulate-pause-play-at-specific-conditions%23new-answer', 'question_page');

          );

          Post as a guest






























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          4
          down vote



          accepted










          Manipulate by default uses Manipulator which doesn't seem to support dynamic values for the AnimationRunning option. However you could use ControlType -> Animator.



          Here's a possible approach where by adding two extra control variables I can stop the animation after i reaches 5 on the first run.



          Manipulate[
          If[initialRun && i >= 5, running = False; initialRun = False];
          Plot[i*Sin[x], x, 0, 10, PlotRange -> 10]
          ,
          initialRun, True, False, ControlType -> None,
          running, True, False, ControlType -> None,
          i, 1, 10, ControlType -> Animator, AnimationRate -> 3,
          RefreshRate -> 60, AnimationRunning -> Dynamic[running]
          ]


          Manipulate with one animation breakpoint



          Note that if the user interacts with the animator before it gets paused by the Manipulate, the pausing will still happen whenever the value of i is 5 or greater first.



          For a version with more than one breakpoint, replace the initialRun boolean with an integer counting how many runs have happened:



          With[breakPoints = 2, 4, 8,
          Manipulate[
          If[runNumber <= Length[breakPoints] && i >= breakPoints[[runNumber]],
          running = False; runNumber++
          ];
          Plot[i*Sin[x], x, 0, 10, PlotRange -> 10]
          ,
          runNumber, 1, ControlType -> None,
          running, True, False, ControlType -> None,
          i, 1, 10, ControlType -> Animator, AnimationRate -> 3, RefreshRate -> 60, AnimationRunning -> Dynamic[running]
          ]
          ]


          Manipulate with several animation breakpoints






          share|improve this answer






















          • +1 Good idea, it seems I am not able to think in this heat. :)
            – Kuba♦
            Aug 8 at 15:42










          • +1, I arrived too late.
            – rhermans
            Aug 8 at 15:44










          • Thank you very much! Great idea, but I would need it to stop when i=5 and then when I push the play button it should continue. Is this possible ?
            – james
            Aug 9 at 5:39










          • Please see the recent edit for more information
            – james
            Aug 9 at 6:12










          • Wow ! This is perfect ! Very well done !! Thank you very much. :))
            – james
            Aug 9 at 8:35














          up vote
          4
          down vote



          accepted










          Manipulate by default uses Manipulator which doesn't seem to support dynamic values for the AnimationRunning option. However you could use ControlType -> Animator.



          Here's a possible approach where by adding two extra control variables I can stop the animation after i reaches 5 on the first run.



          Manipulate[
          If[initialRun && i >= 5, running = False; initialRun = False];
          Plot[i*Sin[x], x, 0, 10, PlotRange -> 10]
          ,
          initialRun, True, False, ControlType -> None,
          running, True, False, ControlType -> None,
          i, 1, 10, ControlType -> Animator, AnimationRate -> 3,
          RefreshRate -> 60, AnimationRunning -> Dynamic[running]
          ]


          Manipulate with one animation breakpoint



          Note that if the user interacts with the animator before it gets paused by the Manipulate, the pausing will still happen whenever the value of i is 5 or greater first.



          For a version with more than one breakpoint, replace the initialRun boolean with an integer counting how many runs have happened:



          With[breakPoints = 2, 4, 8,
          Manipulate[
          If[runNumber <= Length[breakPoints] && i >= breakPoints[[runNumber]],
          running = False; runNumber++
          ];
          Plot[i*Sin[x], x, 0, 10, PlotRange -> 10]
          ,
          runNumber, 1, ControlType -> None,
          running, True, False, ControlType -> None,
          i, 1, 10, ControlType -> Animator, AnimationRate -> 3, RefreshRate -> 60, AnimationRunning -> Dynamic[running]
          ]
          ]


          Manipulate with several animation breakpoints






          share|improve this answer






















          • +1 Good idea, it seems I am not able to think in this heat. :)
            – Kuba♦
            Aug 8 at 15:42










          • +1, I arrived too late.
            – rhermans
            Aug 8 at 15:44










          • Thank you very much! Great idea, but I would need it to stop when i=5 and then when I push the play button it should continue. Is this possible ?
            – james
            Aug 9 at 5:39










          • Please see the recent edit for more information
            – james
            Aug 9 at 6:12










          • Wow ! This is perfect ! Very well done !! Thank you very much. :))
            – james
            Aug 9 at 8:35












          up vote
          4
          down vote



          accepted







          up vote
          4
          down vote



          accepted






          Manipulate by default uses Manipulator which doesn't seem to support dynamic values for the AnimationRunning option. However you could use ControlType -> Animator.



          Here's a possible approach where by adding two extra control variables I can stop the animation after i reaches 5 on the first run.



          Manipulate[
          If[initialRun && i >= 5, running = False; initialRun = False];
          Plot[i*Sin[x], x, 0, 10, PlotRange -> 10]
          ,
          initialRun, True, False, ControlType -> None,
          running, True, False, ControlType -> None,
          i, 1, 10, ControlType -> Animator, AnimationRate -> 3,
          RefreshRate -> 60, AnimationRunning -> Dynamic[running]
          ]


          Manipulate with one animation breakpoint



          Note that if the user interacts with the animator before it gets paused by the Manipulate, the pausing will still happen whenever the value of i is 5 or greater first.



          For a version with more than one breakpoint, replace the initialRun boolean with an integer counting how many runs have happened:



          With[breakPoints = 2, 4, 8,
          Manipulate[
          If[runNumber <= Length[breakPoints] && i >= breakPoints[[runNumber]],
          running = False; runNumber++
          ];
          Plot[i*Sin[x], x, 0, 10, PlotRange -> 10]
          ,
          runNumber, 1, ControlType -> None,
          running, True, False, ControlType -> None,
          i, 1, 10, ControlType -> Animator, AnimationRate -> 3, RefreshRate -> 60, AnimationRunning -> Dynamic[running]
          ]
          ]


          Manipulate with several animation breakpoints






          share|improve this answer














          Manipulate by default uses Manipulator which doesn't seem to support dynamic values for the AnimationRunning option. However you could use ControlType -> Animator.



          Here's a possible approach where by adding two extra control variables I can stop the animation after i reaches 5 on the first run.



          Manipulate[
          If[initialRun && i >= 5, running = False; initialRun = False];
          Plot[i*Sin[x], x, 0, 10, PlotRange -> 10]
          ,
          initialRun, True, False, ControlType -> None,
          running, True, False, ControlType -> None,
          i, 1, 10, ControlType -> Animator, AnimationRate -> 3,
          RefreshRate -> 60, AnimationRunning -> Dynamic[running]
          ]


          Manipulate with one animation breakpoint



          Note that if the user interacts with the animator before it gets paused by the Manipulate, the pausing will still happen whenever the value of i is 5 or greater first.



          For a version with more than one breakpoint, replace the initialRun boolean with an integer counting how many runs have happened:



          With[breakPoints = 2, 4, 8,
          Manipulate[
          If[runNumber <= Length[breakPoints] && i >= breakPoints[[runNumber]],
          running = False; runNumber++
          ];
          Plot[i*Sin[x], x, 0, 10, PlotRange -> 10]
          ,
          runNumber, 1, ControlType -> None,
          running, True, False, ControlType -> None,
          i, 1, 10, ControlType -> Animator, AnimationRate -> 3, RefreshRate -> 60, AnimationRunning -> Dynamic[running]
          ]
          ]


          Manipulate with several animation breakpoints







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 9 at 8:21

























          answered Aug 8 at 15:32









          Gerli

          886512




          886512











          • +1 Good idea, it seems I am not able to think in this heat. :)
            – Kuba♦
            Aug 8 at 15:42










          • +1, I arrived too late.
            – rhermans
            Aug 8 at 15:44










          • Thank you very much! Great idea, but I would need it to stop when i=5 and then when I push the play button it should continue. Is this possible ?
            – james
            Aug 9 at 5:39










          • Please see the recent edit for more information
            – james
            Aug 9 at 6:12










          • Wow ! This is perfect ! Very well done !! Thank you very much. :))
            – james
            Aug 9 at 8:35
















          • +1 Good idea, it seems I am not able to think in this heat. :)
            – Kuba♦
            Aug 8 at 15:42










          • +1, I arrived too late.
            – rhermans
            Aug 8 at 15:44










          • Thank you very much! Great idea, but I would need it to stop when i=5 and then when I push the play button it should continue. Is this possible ?
            – james
            Aug 9 at 5:39










          • Please see the recent edit for more information
            – james
            Aug 9 at 6:12










          • Wow ! This is perfect ! Very well done !! Thank you very much. :))
            – james
            Aug 9 at 8:35















          +1 Good idea, it seems I am not able to think in this heat. :)
          – Kuba♦
          Aug 8 at 15:42




          +1 Good idea, it seems I am not able to think in this heat. :)
          – Kuba♦
          Aug 8 at 15:42












          +1, I arrived too late.
          – rhermans
          Aug 8 at 15:44




          +1, I arrived too late.
          – rhermans
          Aug 8 at 15:44












          Thank you very much! Great idea, but I would need it to stop when i=5 and then when I push the play button it should continue. Is this possible ?
          – james
          Aug 9 at 5:39




          Thank you very much! Great idea, but I would need it to stop when i=5 and then when I push the play button it should continue. Is this possible ?
          – james
          Aug 9 at 5:39












          Please see the recent edit for more information
          – james
          Aug 9 at 6:12




          Please see the recent edit for more information
          – james
          Aug 9 at 6:12












          Wow ! This is perfect ! Very well done !! Thank you very much. :))
          – james
          Aug 9 at 8:35




          Wow ! This is perfect ! Very well done !! Thank you very much. :))
          – james
          Aug 9 at 8:35










          up vote
          2
          down vote













          The credit goes to @Gerli, who arrived first. Difference is that mine uses DynamicModule



          DynamicModule[
          s = True,
          Manipulate[
          If[i > 5, s = False, s = True];
          Plot[i*Sin[x], x, 0, 10, PlotRange -> 10],

          i, 1, 10
          , ControlType -> Animator
          , AnimationRunning -> Dynamic[s]
          ]
          ]


          enter image description here






          share|improve this answer






















          • Thank you very much! I would need it to stop when i=5 and then when I push the play button it should continue. Is this possible ?
            – james
            Aug 9 at 5:39










          • Please have a look at the recent edit. Thanks :)
            – james
            Aug 9 at 6:12














          up vote
          2
          down vote













          The credit goes to @Gerli, who arrived first. Difference is that mine uses DynamicModule



          DynamicModule[
          s = True,
          Manipulate[
          If[i > 5, s = False, s = True];
          Plot[i*Sin[x], x, 0, 10, PlotRange -> 10],

          i, 1, 10
          , ControlType -> Animator
          , AnimationRunning -> Dynamic[s]
          ]
          ]


          enter image description here






          share|improve this answer






















          • Thank you very much! I would need it to stop when i=5 and then when I push the play button it should continue. Is this possible ?
            – james
            Aug 9 at 5:39










          • Please have a look at the recent edit. Thanks :)
            – james
            Aug 9 at 6:12












          up vote
          2
          down vote










          up vote
          2
          down vote









          The credit goes to @Gerli, who arrived first. Difference is that mine uses DynamicModule



          DynamicModule[
          s = True,
          Manipulate[
          If[i > 5, s = False, s = True];
          Plot[i*Sin[x], x, 0, 10, PlotRange -> 10],

          i, 1, 10
          , ControlType -> Animator
          , AnimationRunning -> Dynamic[s]
          ]
          ]


          enter image description here






          share|improve this answer














          The credit goes to @Gerli, who arrived first. Difference is that mine uses DynamicModule



          DynamicModule[
          s = True,
          Manipulate[
          If[i > 5, s = False, s = True];
          Plot[i*Sin[x], x, 0, 10, PlotRange -> 10],

          i, 1, 10
          , ControlType -> Animator
          , AnimationRunning -> Dynamic[s]
          ]
          ]


          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 8 at 15:47

























          answered Aug 8 at 15:42









          rhermans

          21.5k439101




          21.5k439101











          • Thank you very much! I would need it to stop when i=5 and then when I push the play button it should continue. Is this possible ?
            – james
            Aug 9 at 5:39










          • Please have a look at the recent edit. Thanks :)
            – james
            Aug 9 at 6:12
















          • Thank you very much! I would need it to stop when i=5 and then when I push the play button it should continue. Is this possible ?
            – james
            Aug 9 at 5:39










          • Please have a look at the recent edit. Thanks :)
            – james
            Aug 9 at 6:12















          Thank you very much! I would need it to stop when i=5 and then when I push the play button it should continue. Is this possible ?
          – james
          Aug 9 at 5:39




          Thank you very much! I would need it to stop when i=5 and then when I push the play button it should continue. Is this possible ?
          – james
          Aug 9 at 5:39












          Please have a look at the recent edit. Thanks :)
          – james
          Aug 9 at 6:12




          Please have a look at the recent edit. Thanks :)
          – james
          Aug 9 at 6:12












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f179690%2fmanipulate-pause-play-at-specific-conditions%23new-answer', 'question_page');

          );

          Post as a guest













































































          這個網誌中的熱門文章

          How to combine Bézier curves to a surface?

          Mutual Information Always Non-negative

          Why am i infinitely getting the same tweet with the Twitter Search API?