Skip to content

Instantly share code, notes, and snippets.

@chichacha
Created January 26, 2019 05:45
Show Gist options
  • Save chichacha/66804a893e811875776fce747968549c to your computer and use it in GitHub Desktop.
Save chichacha/66804a893e811875776fce747968549c to your computer and use it in GitHub Desktop.
playing with polygon inside of circle
library(tidyverse)
library(magick)
rotating_design <- function(shape=3,m=30){
col_pal <- str_c(ggthemes::tableau_color_pal("Hue Circle")(19),"de") %>%
sample(size=shape)
shape_name_df <- tibble(
shape=c(3,4,5,6,7,8,9,10,12),
name = c("triangle","square","pentagon","hexagon","heptagon",
"octagon","nonagon","decagon","dodecagon")
)
#col_pal <- ggthemes::canva_pal()(4)
df <- tibble(
t = seq(0,2*pi,length.out=(shape*m)+1),
x = cos(t),
y = sin(t),
idx = row_number(t),
g = (idx-0)%%m
)
df %>%
ggplot(aes(x=x,y=y, group=g, color=g)) +
geom_polygon(fill="#00000010", size=1) +
annotate(geom="text",x=0,y=0,label=shape, family="Avenir", size=50, color="#ffffff10") +
theme_void() +
coord_fixed() +
scale_color_gradientn(colors=col_pal,
guide="none") +
theme(panel.background=element_rect(fill="#000000")) +
geom_blank(aes(x=c(-(8/6),(8/6)),y=c(-1,1),group=NULL, color=NULL), data=data.frame())
}
rotating_design(5,25)
rotating_design(5,5)
dev.off()
fig <-image_graph(width=800, height=600)
list(shape=rep(c(3,4,5,6,7,8,9,10,12,9,8,7,6,5,4),each=2),m=rep(c(50,40,20,30,50),each=6)) %>%
pmap(.,rotating_design)
dev.off()
image_animate(fig, fps=10) %>% image_write("Trippy_Circle.gif")
@chichacha
Copy link
Author

trippy_circle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment