Created
August 27, 2021 18:41
-
-
Save ryantimpe/b1a2fcb9fdcd16e80dc0e10eb88ea730 to your computer and use it in GitHub Desktop.
rectthurs_20210826
This file contains 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
#Recreation Thursday | |
# August 26, 2021 | |
#https://twitter.com/kelsey_chalmers/status/1430875667793682432?s=20 | |
library(tidyverse) | |
library(scales) | |
scale_dims = 10 | |
scale_pattern = 1.5 | |
num_x = 22*scale_pattern | |
num_y = 20*scale_pattern | |
sleeve_angle = (5.5/9)*pi | |
main_pattern <- crossing(x = seq(0, num_x*pi*scale_dims, by = 1), | |
y = seq(-1, num_y*pi*scale_dims, by = 1)) %>% | |
mutate( | |
#~~ FABRIC IMPERFECTIONS ~~# | |
#Generate some distortions or ripples in the fabric... | |
#... in the original, none of the waves are perfect | |
#... want to randomly stretch out sections, but in a fluid way | |
# Magic numbers picked haphazardly to purposely not follow the wave pattern | |
fabric_imperfections = sin(x/50*1.5 + y/70*0.8)*sin(x/20*2.1 - y/120*3.4), | |
#~~ WAVES ~~# | |
#ybands tell the waves to shift every other one | |
ybands = (((y/scale_dims)-pi/2)%/%(pi))%%2, | |
#wave boundaries between colors | |
wave = ((y/scale_dims | |
- (2/5)*sin(x/scale_dims + ybands*scale_dims + fabric_imperfections/2)) | |
%/% (pi)) | |
%% 2, | |
#~~ INNER CENTER DESIGN ~~# | |
#These bands turn on/off the checker pattern | |
innerbands = pmax((((y/scale_dims)-pi)%/%(pi))%%2 * (((x/scale_dims)-pi)%/%(pi))%%2, | |
(((y/scale_dims)-pi)%/%(pi)-1)%%2 * (((x/scale_dims)-pi)%/%(pi)-1)%%2), | |
#Define the area of the inner centers with the nested colors | |
inner_center_prep = sin(x/scale_dims + y/scale_dims-pi/2)*sin(x/scale_dims - y/scale_dims-pi/2), | |
inner_center = (inner_center_prep < -0.2 & innerbands == 1) #when to be on | |
* ((inner_center_prep %/% 0.15) %% 2), #The on pattern | |
#~~ FULL PATTERN ~~# | |
#Combine all for a final pattern | |
final_pattern = xor(wave, inner_center) | |
) %>% | |
mutate(fill_pattern = ifelse(final_pattern, "#FDF2EB", "#96514E")) %>% | |
#Start mapping out the pockets, etc | |
mutate( | |
#Bottom pockets have a flat top. Represent this with a Y cut-off | |
pocket_cutoff = x < 8*pi*scale_pattern*scale_dims, | |
#Hacked equation for a "rectircle", rounded corner rectangle. | |
#... lots of trial and error... not sure why I need the ^(10/3) | |
pocket_bl = ( abs((x - ((9-2)/2+2)*pi*scale_pattern*scale_dims)/2)^4 | |
+ abs((y - (-1)*pi*scale_pattern*scale_dims)/1.8)^4) | |
< (4*pi*scale_pattern*scale_dims)^(10/3), | |
pocket_bl = pocket_bl & pocket_cutoff, | |
pocket_br = ( abs((x - ((9-2)/2+2)*pi*scale_pattern*scale_dims)/2)^4 | |
+ abs((y - (16)*pi*scale_pattern*scale_dims)/1.7)^4) | |
< (4*pi*scale_pattern*scale_dims)^(10/3), | |
pocket_br = pocket_br & pocket_cutoff, | |
#Sleeve on the top right | |
sleeve_tr = ( abs((x - (22)*pi*scale_pattern*scale_dims)/2)^2.8 | |
+ abs((y - (20)*pi*scale_pattern*scale_dims)/1.8)^2.8) | |
< (4*pi*scale_pattern*scale_dims)^(8/3), | |
) %>% | |
#Finally, buttons! Top down, all at y=7.5 | |
mutate( | |
button_1 = ((x - 19*scale_dims*pi*scale_pattern)^2 + (y - 7.5*scale_dims*pi*scale_pattern)^2)^(1/2) | |
< (pi/2)*scale_dims*scale_pattern, | |
button_2 = ((x - 14.5*scale_dims*pi*scale_pattern)^2 + (y - 7.5*scale_dims*pi*scale_pattern)^2)^(1/2) | |
< (pi/2)*scale_dims*scale_pattern, | |
button_3 = ((x - 10*scale_dims*pi*scale_pattern)^2 + (y - 7.5*scale_dims*pi*scale_pattern)^2)^(1/2) | |
< (pi/2)*scale_dims*scale_pattern, | |
button_4 = ((x - 5.5*scale_dims*pi*scale_pattern)^2 + (y - 7.5*scale_dims*pi*scale_pattern)^2)^(1/2) | |
< (pi/2)*scale_dims*scale_pattern, | |
) %>% | |
#Add a gradient for each button | |
group_by(b_group = case_when(button_1~1, button_2~2, button_3~3, button_4~4, TRUE~0)) %>% | |
mutate(button_alpha = sin((x+y+row_number())/scale_dims)) %>% | |
ungroup() %>% | |
mutate(button_alpha = ifelse(b_group == 0, -1, button_alpha)) | |
#Here we want to take the Pocket and Sleeve sections and overwrite the pattern in there | |
pattern_pocket_bl <- main_pattern %>% | |
mutate( | |
#The bottom left pocket seems to be shifted 1 entire pattern unit left (decrease y) | |
y = y - round(pi*scale_dims), | |
#Increase x a little for a minor, imperfect shift | |
x = x + round(pi*scale_dims/10) | |
) %>% | |
select(x, y, fill_pattern_bl = fill_pattern) %>% | |
group_by(x,y) %>% | |
filter(row_number()==1) %>% | |
ungroup() | |
pattern_pocket_br <- main_pattern %>% | |
mutate( | |
#The bottom right pocket seems to be shifted a bi tright (increase y) | |
y = y + round(pi*scale_dims*(1/2)), | |
#... and up half a pattern unit | |
x = x - round(pi*scale_dims/2) | |
) %>% | |
select(x, y, fill_pattern_br = fill_pattern) %>% | |
group_by(x,y) %>% | |
filter(row_number()==1) %>% | |
ungroup() | |
pattern_sleeve_tr <- main_pattern %>% | |
mutate( | |
#Sleeve fabric is rotated ~120 degrees | |
#Also we can use the middle of the fabric as a base, not the corner | |
x1 = round( cos(sleeve_angle)*(x+0) + sin(sleeve_angle)*(y+0))+700, | |
y1 = abs(round(-sin(sleeve_angle)*(x+0) + cos(sleeve_angle)*(y+0)))+000 | |
) %>% | |
select(x=x1, y=y1, fill_pattern_tr = fill_pattern) %>% | |
group_by(x,y) %>% | |
filter(row_number()==1) %>% | |
ungroup() | |
#Replace each of the pocket/sleeve sections with their new fill | |
main_pattern2 <- main_pattern %>% | |
left_join(pattern_pocket_bl) %>% | |
left_join(pattern_pocket_br) %>% | |
left_join(pattern_sleeve_tr) %>% | |
mutate(fill_pattern2 = case_when( | |
pocket_bl ~ fill_pattern_bl, | |
pocket_br ~ fill_pattern_br, | |
sleeve_tr ~ fill_pattern_tr, | |
button_1|button_2|button_3|button_4 ~ "#B99282", | |
TRUE ~ fill_pattern)) %>% | |
tidyr::fill(fill_pattern2) %>% | |
#At around 8 patterns into the art, the shirt has it's opening/buttons | |
#Theres a disconnect in the pattern here. | |
filter(!between(y, round(8.4*pi*scale_dims*scale_pattern), | |
round(8.8*pi*scale_dims*scale_pattern))) %>% | |
#Reset the Y values (across) | |
group_by(x) %>% | |
mutate(y = row_number()) %>% | |
ungroup() | |
main_pattern2 %>% | |
ggplot() + | |
aes(y, x) + | |
geom_raster(aes(fill = fill_pattern2)) + | |
scale_fill_identity() + | |
geom_raster(aes(alpha = button_alpha), fill = "#333333") + | |
scale_alpha_continuous(range = c(0, 0.4)) + | |
geom_vline(xintercept = c(8.4)*pi*scale_dims*scale_pattern, | |
color = "#96514E", alpha =0.5, size=1.2) + | |
coord_fixed(expand = FALSE) + | |
labs(caption = "#RecreationThursday | @ryantimpe") + | |
theme_void() + | |
theme( | |
legend.position = "none", | |
plot.caption = element_text(color = "#96514E") | |
) | |
ggsave("recreationthursday_20210826a.png", width = 6, height = 6.1) | |
# | |
# ggsave(filename = paste0("Intermediate_20210826/RT_",str_remove_all(Sys.time(), "[^0-9]"), ".png"), | |
# width = 6, height = 6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment