Skip to content

Instantly share code, notes, and snippets.

@chichacha
Created January 27, 2019 04:55
Show Gist options
  • Save chichacha/31cb640b7dac5c57cc2edfa20ac114f5 to your computer and use it in GitHub Desktop.
Save chichacha/31cb640b7dac5c57cc2edfa20ac114f5 to your computer and use it in GitHub Desktop.
Drawing Rectangles
library(tidyverse)
library(scales)
phi <- (1 + sqrt(5))/2
draw_rect <- function(xr=1,yr=1,name="square") {
df <- tibble(
x=c(0,0,xr,xr,0),
y=c(0,yr,yr,0,0)
)
df_seg <- tibble(x=c(0,xr/sqrt(2),xr/2,xr),y=c(0,yr/sqrt(2),yr/2,yr),
xend=c(0,xr/sqrt(2),xr/2,xr),yend=c(0,yr/sqrt(2),yr/2,yr)) %>%
expand.grid() %>%
filter(!(x==xend&y==yend))
df %>%
ggplot(aes(x=x,y=y)) +
geom_path() +
geom_polygon(fill="#00000030") +
geom_segment(data=df_seg, aes(xend=xend,yend=yend),
size=0.1, color="#000000de") +
coord_fixed() +
theme_void(base_family="Roboto Condensed") +
labs(title=str_to_title(name),x="",y="") +
scale_x_continuous(breaks=scales::pretty_breaks(n=3)) +
scale_y_continuous(breaks=scales::pretty_breaks(n=3)) #+
#expand_limits(x=c(0,3),y=c(0,3))
}
draw_rect(1,sqrt(2),"diagon")
draw_rect(1,1,"square") +
draw_rect(1,sqrt(2),"diagon") +
draw_rect(1,sqrt(3),"hecton") +
draw_rect(1,sqrt(4),"doppelquadrat") +
draw_rect(2,3,"hemiolion") +
draw_rect(1,phi,"auron (golden rectangle)") +
draw_rect(1,sqrt(5)*0.5,"hemidiagon") +
draw_rect(1,sqrt(phi),"penton") +
draw_rect(1,(2/3)*sqrt(3),"trion") +
draw_rect(1,(1+sqrt(2))/2,"quadriagon") +
draw_rect(1,2*phi,"biauron") +
draw_rect(1,2*sqrt((5-2*sqrt(5))),"bipenton")
ggsave(file="Rectangle_Playground3.png", width=16, height=9, dpi=300)
@chichacha
Copy link
Author

rectangle_playground3

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