Skip to content

Instantly share code, notes, and snippets.

@yutannihilation
Created October 1, 2020 15:01
Show Gist options
  • Save yutannihilation/20fd7a8edfdad42ed5b024eb03824793 to your computer and use it in GitHub Desktop.
Save yutannihilation/20fd7a8edfdad42ed5b024eb03824793 to your computer and use it in GitHub Desktop.
library(string2path)
d <- string2path("ABCDE", "/usr/share/fonts/TTF/iosevka-extrabold.ttf")
colnames(d) <- c("x", "y", "group")
d$subgroup <- 1
library(triangular)
library(ggplot2)
m <- as.matrix(d[,1:2])
m %*% matrix(c(cos(1), -sin(1), sin(1), cos(1)), nrow = 2, ncol = 2) %>%
as.data.frame()
rot <- function(m, theta, x, y) {
rot <- rbind(
c(cos(theta), -sin(theta), 0),
c(sin(theta), cos(theta), 0),
c(0, 0, 1)
)
mov <- rbind(
c(1, 0, x),
c(0, 1, y),
c(0, 0, 1)
)
m %*% mov %*% rot %*% -mov
}
zoom <- function(m, zoom, x, y) {
zoom <- rbind(
c(zoom, 0, 0),
c(0, zoom, 0),
c(0, 0, 1)
)
mov <- rbind(
c(1, 0, x),
c(0, 1, y),
c(0, 0, 1)
)
m %*% -mov %*% zoom %*% mov
}
plot_frame <- function(i) {
m_orig <- cbind(
d$x + (d$x - 10)^2 / 10 * sin(sin(i / 100) * (d$y - 4)),
d$y + sin(sin(i / 100) * (d$y - 4)),
1
)
r1 <- (1 - sqrt(d$x^2 + d$y^2) / sqrt(max(d$x)^2 + max(d$y)^2))^3
m <- zoom(m_orig, 1 + i / 30, 11, 4.1)
m <- r1 * m_orig + (1 - r1) * m
m <- rot(m, pi / 12 * sin(i / 30), 11.4, 3.9)
r2 <- (1 - sqrt(d$x^2 + d$y^2) / sqrt(max(d$x)^2 + max(d$y)^2))^4
m <- zoom(m_orig, 1 + 0.2 * sqrt(i / 3), 9, 3.5)
m <- r2 * m_orig + (1 - r2) * m
m <- rot(m, -pi / 12 * sin(sqrt(i / 1000)), 13, 4)
m <- r2 * m_orig + (1 - r2) * m
d[,1:2] <- m[,1:2]
d$x <- d$x + (d$x - 8)^2 / 10 * sin(7.3 * sin(i / 444) * (d$y - 3.3))
d$y <- d$y + sin(0.3 * sin(i / 78) * (d$y - 4))
x <- decompose(d)
ggplot(x) +
geom_polygon(aes(x, y, group = as.factor(idx))) +
theme_bw() +
coord_equal(xlim = c(-5, 25), ylim = c(-3, 10))
}
gifski::save_gif(
for (i in 0:120) {
message(i)
print(plot_frame(i / 3))
},
delay = 0.05
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment