Created
January 27, 2019 00:57
-
-
Save chichacha/556150422ccbba9cbb6e2da7beea1cf0 to your computer and use it in GitHub Desktop.
HalfCircles & Triangles
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(tidyverse) | |
#half_circle | |
half_circle <- function(xc=0,yc=0,r=1,shift=0,points=100,...){ | |
df <- tibble( | |
t = seq(shift ,pi+shift,length.out=points), | |
x = xc + r*cos(t), | |
y = yc + r*sin(t) | |
) | |
return(df %>% select(x,y)) | |
} | |
## arrangement | |
make_df <- function(xn=32, yn=20, spinby=pi/4, alpha="20", points=3){ | |
under_the_sea <- c("#2D355A", "#255498", "#E299B0", "#FA7268", "#009698", "#7E874B", "#FFDC01", "#94DBDF") | |
grid <- tibble( | |
xc = rep(c(1:xn),each=yn), | |
yc = rep(c(1:yn),times=xn), | |
r = 0.5, | |
points=points, | |
shift = sample(seq(0,2*pi,by=spinby),size=xn*yn, replace=T), | |
color = str_c(sample(under_the_sea, size=xn*yn, replace=T),alpha) | |
) %>% | |
mutate(group=row_number()) %>% | |
mutate(df = pmap(.,half_circle)) %>% | |
unnest(df) | |
return(grid) | |
} | |
make_df() | |
make_df() %>% | |
ggplot(aes(x=x,y=y, group=group,fill=color)) + | |
geom_polygon() + | |
geom_polygon(data=make_df(spinby=pi/2,alpha="90")) + | |
geom_polygon(data=make_df(spinby=pi/2,alpha="10")) + | |
geom_polygon(data=make_df(spinby=pi/4,alpha="ae")) + | |
theme_void() + | |
coord_fixed() + | |
scale_fill_identity() | |
ggsave(file="TriangleDesign.png", width=16, height=10, type="cairo") |
Author
chichacha
commented
Jan 27, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment