Created
March 12, 2021 00:20
-
-
Save yjunechoe/892b090c7e87b3f6c0278f528d510213 to your computer and use it in GitHub Desktop.
Draw the Chrome icon from Font Awesome using {string2path} - https://github.com/yutannihilation/string2path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(ggplot2) | |
library(gganimate) | |
# Path to Font Awesome 5 Brands ttf file | |
fa_brands <- paste0( | |
Sys.getenv("FONT_PATH"), | |
"Font-Awesome-5-Brands-Regular-400.ttf" | |
) | |
# Grab coordinates of the chrome icon | |
# https://github.com/yutannihilation/string2path | |
chrome_icon <- string2path::string2path( | |
str = intToUtf8(strtoi("f268", 16)), # Convert to unicode glyph | |
ttf_file = fa_brands | |
) %>% | |
mutate( | |
id = factor(id), | |
point_id = row_number() | |
) | |
# Animation | |
chrome_draw <- chrome_icon %>% | |
ggplot(aes(x, y, group = id)) + | |
geom_polygon( | |
aes(fill = id), | |
color = 'white', | |
data = chrome_icon %>% | |
group_by(id) %>% | |
mutate(point_id = max(point_id)) | |
) + | |
geom_path( | |
aes(color = id), | |
size = 2 | |
) + | |
coord_equal() + | |
scale_color_manual( | |
values = c("#CC0033", "#0099FF", "#FDD20A", "#019934"), | |
guide = guide_none() | |
) + | |
scale_fill_manual( | |
values = c("#CC0033", "#0099FF", "#FDD20A", "#019934"), | |
guide = guide_none() | |
) + | |
theme_void() + | |
transition_reveal(point_id) | |
animate( | |
chrome_draw, | |
renderer = av_renderer(), | |
device = ragg::agg_png(res = 300), | |
end_pause = 10 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment