Created
September 21, 2021 03:05
-
-
Save yutannihilation/b4ba063784153b7dcf23a4afa1c3b674 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(string2path) | |
library(ggplot2) | |
d <- string2path("?", "/usr/share/fonts/truetype/roboto/unhinted/RobotoTTF/Roboto-BoldItalic.ttf") | |
f <- function(d, theta) { | |
d <- dplyr::mutate(d, x = x + 0.02 * cos(theta * 3.2), y = y + 0.02 * sin(theta * 2.1)) | |
d2 <- dplyr::bind_rows( | |
dplyr::mutate(d, glyph_id = 1, path_id = sprintf("%d-%d", glyph_id, path_id), rgb = "#ff0000", x = x + rnorm(1, sd = 0.008), y = y + rnorm(1, -0.001, sd = 0.007)), | |
dplyr::mutate(d, glyph_id = 2, path_id = sprintf("%d-%d", glyph_id, path_id), rgb = "#00ff00", x = x + rnorm(1, sd = 0.008), y = y + rnorm(1, 0.000, sd = 0.007)), | |
dplyr::mutate(d, glyph_id = 3, path_id = sprintf("%d-%d", glyph_id, path_id), rgb = "#0000ff", x = x + rnorm(1, sd = 0.008), y = y + rnorm(1, +0.001, sd = 0.007)) | |
) | |
p <- ggplot() + | |
geom_polygon(data = d2, aes(x, y, group = path_id, fill = rgb), alpha = 0.5) + | |
geom_polygon(data = d, aes(x, y, group = path_id), fill = "black") + | |
theme_minimal() + | |
coord_equal(xlim = c(-0.05, 0.45), ylim = c(-0.05, 0.55)) + | |
theme(legend.position = "top") + | |
scale_fill_identity() | |
invisible(plot(p)) | |
} | |
gifski::save_gif( | |
for (i in 1:120) { | |
f(d, 2 * pi * i / 120) | |
}, | |
delay = 1/60 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment