Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListAnimate with controls like a slideshow

This may be an abuse of ListAnimate but I'm using it to flip through a bunch of images. When there are few enough images I can grab the slider with the mouse and flip back and forth among the images easily enough.

But when there are too many it's very tricky to flip through them one by one. Is there a way to simply use the arrow keys (or whatever keys) to flip forward and backward through the images, kind of like a slideshow?

like image 230
dreeves Avatar asked Feb 24 '23 14:02

dreeves


1 Answers

Here's a simple keyboard controlled slideshow:

SlideShow[list_List] := 
 With[{len = Length[list]}, DynamicModule[{pos = 1}, 
      EventHandler[Dynamic[Pane[list[[pos]]]], 
                {"RightArrowKeyDown" :> (pos = Mod[pos + 1, len, 1]), 
                 "LeftArrowKeyDown" :> (pos = Mod[pos - 1, len, 1]), 
                 "UpArrowKeyDown" :> (pos = 1), 
                 "DownArrowKeyDown" :> (pos = len)}]]]

Then you control the slideshow by selecting the output and using the arrow keys:
right=forward, left=back, up=first, down=last,

For example:

SlideShow[{"a","b","c","d"}]

Some example pictures:

pics = ExampleData /@ ExampleData["TestImage"][[{1, 2, 3, 4}]]

SlideShow@pics

(* Imagine a screen capture here *)

This can be dressed up to give it a frame, buttons, etc...

like image 68
Simon Avatar answered Mar 04 '23 13:03

Simon