Skip to content

Instantly share code, notes, and snippets.

@djnavarro
Created January 30, 2019 11:17
Show Gist options
  • Save djnavarro/4f8a10dba75fe9663374c9e06e8a453f to your computer and use it in GitHub Desktop.
Save djnavarro/4f8a10dba75fe9663374c9e06e8a453f to your computer and use it in GitHub Desktop.
animated thank you message made from stars
# devtools::install_github("yixuan/fontr")
library(fontr)
library(transformr)
library(showtext)
library(tidyverse)
library(gganimate)
# use showtext to loading Google fonts (http://www.google.com/fonts)
font_add_google("Allura")
# use fontr to construct outlines
get_letter <- function(ch, xshift, yshift, id) {
char_poly <- glyph_polygon(ch, family = "Allura", face = "regular", nseg = 20)
char_poly$x <- char_poly$x * 1.9
char_poly$y <- char_poly$y * 1.9
char_poly$x <- char_poly$x + xshift
char_poly$y <- char_poly$y + yshift
char_poly$id <- id
return(char_poly)
}
# use the transformr simple shapes
get_shape <- function(xshift, yshift, id) {
shape_poly <- poly_star()
shape_poly$y <- shape_poly$y + 1
shape_poly$x <- shape_poly$x / 2.5
shape_poly$y <- shape_poly$y / 2.5
shape_poly$x <- shape_poly$x + xshift
shape_poly$y <- shape_poly$y + yshift
shape_poly$id <- id
return(shape_poly)
}
sep <- .75
# text message in frame 2
msg <- bind_rows(
get_letter("T", 1.2, sep, 1),
get_letter("h", 2.2, sep, 2),
get_letter("a", 3.1, sep, 3),
get_letter("n", 4.0, sep, 4),
get_letter("k", 4.8, sep, 5),
get_letter("Y", 2.2, -sep, 6),
get_letter("o", 3.2, -sep, 7),
get_letter("u", 3.9, -sep, 8)
)
# shapes in frame 1
shapes <- bind_rows(
get_shape(1.5,sep,1),
get_shape(2.4,sep,2),
get_shape(3.3,sep,3),
get_shape(4.2,sep,4),
get_shape(5.1,sep,5),
get_shape(2.4,-sep,6),
get_shape(3.3,-sep,7),
get_shape(4.2,-sep,8)
)
# assign them to frames and bind
msg$frame <- 2
shapes$frame <- 1
dat <- bind_rows(msg,shapes)
# define the animation
anim <- dat %>% ggplot(aes(x,y,group=id)) +
geom_path(size = 1.5) +
coord_equal() +
ylim(-2, 3) +
theme_void() +
transition_states(frame)
# create it
animate(anim, type = "cairo")
anim_save("~/../Desktop/thank_you_stars.gif")
@djnavarro
Copy link
Author

thank_you_stars

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment