Controlling timing of return from function

I'm trying to create a GIF with a text overlay where the overlay will change at a one-second interval. Because of the large number of individual GIFs necessary, I ended up wrapping the image_annotate function (from magick package) in a function to return the result more rapidly. I feel like there might be a way to use Sys.sleep() to delay the function return to every second, but I haven't been able to get it working. TIA if anyone has suggestions I could try.

library(tidyverse) 
library(magick) 

falls_gif <- image_read('https://media.giphy.com/media/jpxjacGJcdies/giphy.gif')

annotation <- function(x,y){
images = x:y %>% map(~image_annotate(falls_gif[seq(1,15,4)], 
                                     paste0("Acre-Feet: ", 2*.x), size=20, color="white"))
  return(images)

}

annotation(x=0, y=250)

Your annotation function returns a list of gifs. Each gif is the same (it's composed of one-fourth of the frames in falls_gif, but I'll refer to it as falls_gif for brevity), except for the different value of the annotated number in the upper left corner. In my answer to your previous question, the code stacks each copy of falls_gif into a single gif where the annotated number increments in whatever time it takes for falls_gif to run. Are you saying that you want this number to increment once per second, rather than incrementing once per whatever amount of time it takes for falls_gif to run? I just want to make sure I understand your question.

@joels, thanks for your replies (on my previous question and this one). Yes, I am trying to get the annotated numbers to increment once per second as opposed to once per whatever amount of time it takes for falls_gif to run.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.