Skip to content

Instantly share code, notes, and snippets.

@yutannihilation
Created November 23, 2018 01:49
Show Gist options
  • Save yutannihilation/69c2ec5476469fea723def0b0cdeedaa to your computer and use it in GitHub Desktop.
Save yutannihilation/69c2ec5476469fea723def0b0cdeedaa to your computer and use it in GitHub Desktop.
library(tidyverse)
library(magick)
steps <- 10000L
coil_turns <- 3L
max_r <- coil_turns * 2 * pi
imgs <- image_graph(300, 300, res = 30)
rotation <- pi/4
for (rotation in pi/64 * 1:128) {
d <- tibble(
radius = 2 * pi * seq(0, steps) / steps * coil_turns,
phi = radius - rotation,
x = cos(phi) + radius * sin(phi),
y = sin(phi) - radius * cos(phi)
)
p <- ggplot(d) +
geom_path(aes(x, y)) +
theme_minimal() +
coord_equal() +
xlim(-max_r, max_r) +
ylim(-max_r, max_r)
print(p)
}
dev.off()
animation <- image_animate(imgs, fps = 25)
image_write(animation, "involute.gif")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment