2
$\begingroup$

Imagine I have a certain list of Graphics-type objects that I then incorporate into ListAnimate

ListAnimate[
 Table[Graphics[Circle[RandomReal[1, 2], RandomReal[1, 2]]], {j, 20}],
  ImageSize -> Tiny, ControlPlacement -> Top]

enter image description here

Now, I want to define a Button, so that, upon clicked, it prints the current frame on ListAnimate. How do I do that? I was wondering if it's possible to track the current iterator in a dynamic way, perhaps by accessing the Animator within ListAnimate. Any ideas?

$\endgroup$

3 Answers 3

5
$\begingroup$
t = Table[Graphics[Circle[RandomReal[1, 2], RandomReal[1, 2]]], 20];

We can add a button in Manipulate to paste the current content in the next cell:

pasteButton = Button[Pane["Paste", ImageSize -> {250, Automatic}, 
     Alignment -> Center],
    SelectionMove[EvaluationNotebook[], Next, Cell];
    NotebookWrite[EvaluationNotebook[], ToBoxes@#]; 
    SelectionMove[EvaluationNotebook[], Previous, Cell]; 
    SelectionMove[EvaluationNotebook[], After, CellContents]] &;

Manipulate[t[[i]], 
 {{i, 1}, Range[20], Animator, AnimationRunning -> False, 
  ImageSize -> 250,
  AppearanceElements ->
   {"ProgressSlider", "StepLeftButton", "StepRightButton", 
    "PlayPauseButton", "DirectionButton"}},
 Dynamic @ pasteButton[t[[i]]],
 ContentSize -> {250, 200}, Alignment -> Center]

enter image description here

Update: Organize buttons in a row:

pasteButton2 = 
  Button[Style["Paste", 10], 
    SelectionMove[EvaluationNotebook[], Next, Cell];
    NotebookWrite[EvaluationNotebook[], ToBoxes@#];
    SelectionMove[EvaluationNotebook[], Previous, Cell];
    SelectionMove[EvaluationNotebook[], After, CellContents]] &;

Manipulate[t[[i]], 
 Row[{Control @ {{i, 1}, Range[20], Animator, AnimationRunning -> False,
      ImageSize -> 250, 
     AppearanceElements -> {"ProgressSlider", "FasterSlowerButtons", 
       "PlayPauseButton", "DirectionButton"}}, 
   Dynamic @ pasteButton2[t[[i]]]}], ContentSize -> {300, 200}, 
 Alignment -> Center]

enter image description here

$\endgroup$
2
  • $\begingroup$ Would it be possible to include the "Paste" button as a small button together with the AppearanceElements? $\endgroup$
    – sam wolfe
    Aug 14, 2021 at 12:10
  • $\begingroup$ @samwolfe, please see the update. $\endgroup$
    – kglr
    Aug 14, 2021 at 23:27
3
$\begingroup$
t = Table[Graphics[Circle[RandomReal[1, 2], RandomReal[1, 2]]], 20];

You can use DynamicSetting and EvaluateInPlace to turn the code into a Manipulate object that works like a button to paste the current content in the next cell.

DynamicSetting @ Manipulate[t[[i]], 
 {{i, 1}, Range[20], Animator, AnimationRunning -> False}, 
 ContentSize -> {300, 300}, Alignment -> Center]

Highlight the code and hit Control+Shift+Enter. Then, you can paste the current content in the next cell by using Shift+Enter.

enter image description here

$\endgroup$
4
  • $\begingroup$ What is your screen capture solution? $\endgroup$
    – Syed
    Aug 12, 2021 at 22:53
  • $\begingroup$ @Syed, I am using ScreenToGIF $\endgroup$
    – kglr
    Aug 12, 2021 at 23:09
  • $\begingroup$ ,,, and how do you make these buttons? Thanks for both the responses. $\endgroup$
    – Syed
    Aug 12, 2021 at 23:16
  • $\begingroup$ @Syed, you can use the Edit button under my post the see how the buttons are made. $\endgroup$
    – kglr
    Aug 12, 2021 at 23:50
2
$\begingroup$

Try the following code, and think about it some more. You don't need both the ListAnimate and Manipulate.

ListAnimate[
 t = Table[
   Graphics[
    Circle[RandomReal[1, 2], RandomReal[1, 2]]],
   20
   ],
 ImageSize -> {200, 200},
 ControlPlacement -> Top,
 AnimationRunning -> False
 ]

I have made a few minor changes. 't' is a table that contains "Graphics" for the 20 frames. You can move t=Table[ ... ] outside the ListAnimate and evaluate it first and later use only t inside the ListAnimate.

OR you could use Manipulate on the table directly..

Manipulate[
 t[[i]],
 {{i, 1}, Range[20]},
 ContentSize -> {400, 200},
 ControlType -> Setter
 ]

enter image description here

Investigate other ControlType options. I hope it helps.

$\endgroup$
1
  • 1
    $\begingroup$ Using ControlType -> Animator in Manipulate you get the same look as ListAnimate , and you can use the $\bigoplus$ menu to paste the code for the current frame in the next cell (+1) $\endgroup$
    – kglr
    Aug 12, 2021 at 21:26

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.