Skip to content

Instantly share code, notes, and snippets.

@MartinMSPedersen
Created March 28, 2019 11:57
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 MartinMSPedersen/6e5a9aa182d49d196ab5bc7c1d4e26c6 to your computer and use it in GitHub Desktop.
Save MartinMSPedersen/6e5a9aa182d49d196ab5bc7c1d4e26c6 to your computer and use it in GitHub Desktop.
polygon <- function(n) {
tibble(
x = accumulate(1:(n-1), ~.x+cos(.y*2*pi/n), .init = 0),
y = accumulate(1:(n-1), ~.x+sin(.y*2*pi/n), .init = 0),
xend = accumulate(2:n, ~.x+cos(.y*2*pi/n), .init = cos(2*pi/n)),
yend = accumulate(2:n, ~.x+sin(.y*2*pi/n), .init = sin(2*pi/n)))
}
ggplot(polygon(5) + geom_segment(aes(x=x, y=y, xend=xend, yend=yend)) + theme_void() + coord_equal()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment