Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement Request: Animation for Individual game #9

Open
pssguy opened this issue Jul 24, 2016 · 6 comments
Open

Enhancement Request: Animation for Individual game #9

pssguy opened this issue Jul 24, 2016 · 6 comments
Milestone

Comments

@pssguy
Copy link

pssguy commented Jul 24, 2016

For example any of the chesswc games
This would entail creating a plot for every move and combining them - using ?animation package

@pssguy
Copy link
Author

pssguy commented Jul 24, 2016

Actually, the new magick package may be better approach

@jbkunst
Copy link
Owner

jbkunst commented Jul 28, 2016

Hi @pssguy

Tell me if this looks good to you.

library("magick")
get_gif <- function(pgn, scale = "400x400", fps = 1) {

  fens <- get_fens(pgn)
  # fens <- head(fens)

  fens %>% 
    map(ggchessboard) %>% 
    map_chr(function(p){ # p <- sample(plots, size = 1)[[1]]
    fl <- tempfile(fileext = ".jpg")
    ggplot2::ggsave(p, file = fl)
    fl
  }) %>% 
    image_read() %>% 
    image_scale(geometry = scale) %>% 
    image_animate(fps = fps)


}

gif <- get_gif(pgn)

image_write(gif, "anim.gif")

anim

I need to change the font to have a nicer look but is a start.

I you're ok I will proceed to add this utilities into the package! :B

@pssguy
Copy link
Author

pssguy commented Jul 28, 2016

This is amazing work
Any reason you chose jpg over png?

Currently it is set to fps=1. I found 0.2 gave me time to take in moves better (same file size)

Ideally, somehow for users there would be controls to pause, set speed etc. but I have no idea if this is even feasible

@jbkunst
Copy link
Owner

jbkunst commented Aug 1, 2016

No reason, just copy paste code from somewhere.

Not sure yet too how to implement parameters for have control in the image_animate. I'll take some time to see if this is feasible in a simple way.

@jbkunst jbkunst added this to the v0.2.0 milestone Aug 2, 2016
@sjorsvanheuveln
Copy link

What about plotting this animation in R-Studio? So not saving as a file but real time plot a game. I cannot do it, as the plot won't refresh in a for loop. How to solve this?

@jbkunst
Copy link
Owner

jbkunst commented Sep 28, 2016

I guess it's possible wrap the image in a html div using htmltools package and then use the browseable function to send it to the viewer.

Let me if you can try this idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants