Skip to content

Instantly share code, notes, and snippets.

@yjunechoe
Created April 5, 2021 02:15
Show Gist options
  • Select an option

  • Save yjunechoe/b62bf14257f6f9c4bcde67299f830347 to your computer and use it in GitHub Desktop.

Select an option

Save yjunechoe/b62bf14257f6f9c4bcde67299f830347 to your computer and use it in GitHub Desktop.
library(dplyr)
library(ggplot2)
library(gganimate)
library(string2path)
magic <- string2path(
"MAGIC",
paste0(Sys.getenv("FONT_PATH"), "xkcd.ttf")
)
magic_points <- magic %>%
group_by(glyph_id) %>%
mutate(across(c(x, y), ~ min(.x) + (max(.x) - min(.x))/2, .names = "{.col}1")) %>%
rename(x2 = x, y2 = y) %>%
# "letter spacing"
mutate(across(starts_with("x"), ~ .x + seq(-5, 5, length.out = 5)[cur_group_id()])) %>%
ungroup()
magic_points %>%
tidyr::pivot_longer(
matches("^[xy]"),
names_to = c(".value", "state"),
names_pattern = "(.)(.)"
) %>%
ggplot(aes(x, y, group = glyph_id, fill = factor(glyph_id))) +
geom_polygon(show.legend = FALSE) +
scale_fill_manual(values = colorspace::rainbow_hcl(6, c = 80)) +
theme_void() +
transition_states(state) +
ease_aes("bounce-in-out")
@yjunechoe
Copy link
Copy Markdown
Author

anim

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