Skip to content

Instantly share code, notes, and snippets.

@yutannihilation
Last active September 26, 2021 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yutannihilation/1edefe7be052970d6609b52c657514fa to your computer and use it in GitHub Desktop.
Save yutannihilation/1edefe7be052970d6609b52c657514fa to your computer and use it in GitHub Desktop.
library(ggplot2)
library(string2path)
library(dplyr, warn.conflicts = FALSE)
library(gganimate)
f <- systemfonts::system_fonts()
# This is reproducible but only on my laptop, sorry for my laziness...
set.seed(100)
some_fonts <- sample(f$path[tools::file_ext(f$path) %in% c("ttf", "otf")], 30)
# remove failed fonts
some_fonts <- some_fonts[c(1, 2, 3, 5, 7, 9, 10, 11, 15, 16, 17, 19, 20, 21, 22, 24, 25, 26, 28, 29, 30)]
names(some_fonts) <- seq_along(some_fonts)
d <- purrr::map_dfr(some_fonts, \(font) {
string2path::string2path("0.0.3", font)
}, .id = "id")
d2 <- d |>
mutate(
x_center = (max(x) - min(x)) / 2,
y_center = (max(y) - min(y)) / 2
) |>
group_by(id) |>
mutate(
x = x - (max(x) - min(x)) / 2 + x_center,
y = y - (max(y) - min(y)) / 2 + y_center
) |>
ungroup()
d2_bg <- d2 |>
mutate(group = paste(id, path_id, glyph_id)) |>
select(!id)
anim <- d2 |>
ggplot() +
geom_path(data = d2_bg, aes(x, y, group = group), colour = alpha("grey", 0.5), size = 2) +
geom_path(aes(x, y, colour = id, group = paste(path_id, glyph_id)), size = 2) +
scale_colour_viridis_d(option = "F", end = 0.7) +
coord_equal() +
theme_minimal() +
guides(colour = "none") +
ease_aes('cubic-in-out') +
transition_states(id, transition_length = 5)
anim_save("anim.gif", anim, nframes = 150, fps = 60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment