commit 7d48643a169e61b8dfebbc3540741c1638d789fc Author: Ryan Timpe Date: Sat Apr 21 15:26:32 2018 -0400 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aaab286 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.Rproj.user +.Rhistory +.RData +.Ruserdata +Lego.Rproj diff --git a/0_Playground.R b/0_Playground.R new file mode 100644 index 0000000..361de03 --- /dev/null +++ b/0_Playground.R @@ -0,0 +1,201 @@ +library(tidyverse); library(jpeg) + +img.raw <- readJPEG("Images/anthonyryan.jpg") + +img <- bind_rows( + list( + (as.data.frame(img.raw[, , 1]) %>% + mutate(y=row_number(), channel = "R") %>% + gather(x, value, -y, -channel) %>% + mutate(x = as.numeric(gsub("V", "", x)))), + (as.data.frame(img.raw[, , 2]) %>% + mutate(y=row_number(), channel = "G") %>% + gather(x, value, -y, -channel) %>% + mutate(x = as.numeric(gsub("V", "", x)))), + (as.data.frame(img.raw[, , 3]) %>% + mutate(y=row_number(), channel = "B") %>% + gather(x, value, -y, -channel) %>% + mutate(x = as.numeric(gsub("V", "", x)))) + ) +) %>% + # mutate(value = value * 255) %>% + spread(channel, value) + +#Goal is 48 px tall + +max(img$x) +max(img$y) + +img_height <- 48 + +img2 <- img %>% + mutate(y_scaled = (y - min(y))/(max(y)-min(y))*img_height + 1, + x_scaled = (x - min(x))/(max(x)-min(x))*img_height + 1) %>% + group_by(y2 = ceiling(y_scaled), x2 = ceiling(x_scaled)) %>% + summarize_at(vars(R, G, B), funs(mean(.))) %>% + rowwise() %>% + mutate(color = rgb(R, G, B)) %>% + ungroup() + +ggplot(img2 %>% filter(x2 <= 100), aes(x=x2, y=-y2, fill = color)) + + geom_raster()+ + scale_fill_identity() + + coord_fixed(expand = FALSE) + +#Lego colors +lego_colors <- read_csv("Colors/Lego_Colors.csv") + +lego_colors2 <- lego_colors %>% + filter(c_Palette2016, !c_Transparent, !c_Glow, !c_Metallic) %>% + mutate_at(vars(R, G, B), funs(./255)) %>% + rename(R_lego = R, G_lego = G, B_lego = B)%>% + mutate_at(vars(starts_with("w_")), funs(ifelse(is.na(.), 0, .))) + +lego_colors3 <- lego_colors2 %>% + filter(t_Classic) + +convert_to_lego <- function(R, G, B){ + + dat <- lego_colors2 %>% + mutate(dist = ((R_lego - R)^2 + (G_lego - G)^2 + (B_lego - B)^2)^(1/2)) %>% + # mutate(dist = dist^w_Classic) %>% + filter(dist == min(dist)) %>% + top_n(1, dist) + + return(data.frame(Lego_name = dat$Color, + Lego_color = rgb(dat$R_lego, dat$G_lego, dat$B_lego), + stringsAsFactors = F)) + +} + +l_img2 <- img2 %>% + # filter(x2 <= 100) %>% + mutate(lego = purrr::pmap(list(R, G, B), convert_to_lego)) %>% + unnest(lego) + +ggplot(l_img2, aes(x=x2, y=-y2, fill = Lego_color)) + + geom_tile(width = 0.9, height = 0.9)+ + scale_fill_identity() + + geom_point(color = "#333333", alpha = 0.2, shape = 1, size = 2.5) + + coord_fixed(expand = FALSE) + + theme_minimal()+ + theme(panel.background = element_rect(fill = "#999999"), + axis.title.x = element_blank(), + axis.text.x = element_blank(), + axis.title.y = element_blank(), + axis.text.y = element_blank()) + + +#Combine bricks into larger ones +#Give each theoretical brick a unique ID + +l_img3 <- l_img2 %>% + select(x=x2, y=y2, Lego_name, Lego_color) %>% + #4x2 bricks - horizontal + group_by(xg = x %/% 4, yg = y %/% 2) %>% + mutate(g_1_x4y2_0 = ifelse(length(unique(Lego_name)) == 1 & n() == 8, + paste0("x4y2_", "x", min(x), "_y", min(y)), NA)) %>% + ungroup() %>% + #4x2 bricks - vertical + group_by(xg = x %/% 2, yg = y %/% 4) %>% + mutate(g_2_x2y4_0 = ifelse(length(unique(Lego_name)) == 1 & n() == 8, + paste0("x2y4_", "x", min(x), "_y", min(y)), NA)) %>% + ungroup() %>% + # #4x2 bricks - horizontal offset + # group_by(xg = (x+2) %/% 4, yg = (y+1) %/% 2) %>% + # mutate(g_3_x4y2_1 = ifelse(length(unique(Lego_name)) == 1 & n() == 8, + # paste0("x4y2_", "x", min(x), "_y", min(y)), NA)) %>% + # ungroup() %>% + # #4x2 bricks - vertical offset + # group_by(xg = (x+1) %/% 2, yg = (y+2) %/% 4) %>% + # mutate(g_4_x2y4_1 = ifelse(length(unique(Lego_name)) == 1 & n() == 8, + # paste0("x2y4_", "x", min(x), "_y", min(y)), NA)) %>% + # ungroup() %>% + #2x2 bricks + group_by(xg = x %/% 2, yg = y %/% 2) %>% + mutate(g_5_x2y2_0 = ifelse(length(unique(Lego_name)) == 1 & n() == 4, + paste0("x2y2_", "x", min(x), "_y", min(y)), NA)) %>% + ungroup() %>% + # #2x2 bricks - offset + # group_by(xg = (x+1) %/% 2, yg = (y+1) %/% 2) %>% + # mutate(g_6_x2y2_1 = ifelse(length(unique(Lego_name)) == 1 & n() == 4, + # paste0("x2y2_", "x", min(x), "_y", min(y)), NA)) %>% + # ungroup() %>% + #4x1 bricks - horizontal + group_by(xg = x %/% 4, yg = y ) %>% + mutate(g_7_x4y1_0 = ifelse(length(unique(Lego_name)) == 1 & n() == 4, + paste0("x4y1_", "x", min(x), "_y", min(y)), NA)) %>% + ungroup() %>% + #4x1 bricks - vertical + group_by(xg = x, yg = y %/% 4) %>% + mutate(g_8_x1y4_1 = ifelse(length(unique(Lego_name)) == 1 & n() == 4, + paste0("x1y4_", "x", min(x), "_y", min(y)), NA)) %>% + ungroup() %>% + #3x1 bricks - horizontal + group_by(xg = x %/% 3, yg = y ) %>% + mutate(g_7_x3y1_0 = ifelse(length(unique(Lego_name)) == 1 & n() == 3, + paste0("x3y1_", "x", min(x), "_y", min(y)), NA)) %>% + ungroup() %>% + #3x1 bricks - vertical + group_by(xg = x, yg = y %/% 3) %>% + mutate(g_8_x1y3_1 = ifelse(length(unique(Lego_name)) == 1 & n() == 3, + paste0("x1y3_", "x", min(x), "_y", min(y)), NA)) %>% + ungroup() %>% + #2x1 bricks - horizontal + group_by(xg = x %/% 2, yg = y ) %>% + mutate(g_9_x2y1_0 = ifelse(length(unique(Lego_name)) == 1 & n() == 2, + paste0("x2y1_", "x", min(x), "_y", min(y)), NA)) %>% + ungroup() %>% + #2x1 bricks - vertical + group_by(xg = x, yg = y %/% 2) %>% + mutate(g_10_x1y2_1 = ifelse(length(unique(Lego_name)) == 1 & n() == 2, + paste0("x1y2_", "x", min(x), "_y", min(y)), NA)) %>% + ungroup() %>% + #1x1 + mutate(g_11_x1y1_0 = paste0("x1y1_", "x", x, "_y", y)) %>% + select(-xg, -yg) + +l_img4 <- l_img3 %>% + gather(Brick, brick_id, dplyr::starts_with("g_")) %>% + #Only keep first Brick group that is true...biggest ones are first! + group_by(x, y) %>% + filter(Brick == Brick[min(which(!is.na(brick_id)))]) %>% + ungroup() + +l_img5 <- l_img4 %>% + group_by(brick_id) %>% + mutate(brick_size = n()) %>% #HMMMnot perfect. some overlap with assignments + ungroup() %>% + group_by(brick_id) %>% + mutate(xmin = min(x)-0.5, xmax = max(x)+0.5, + ymin = min(y)-0.5, ymax = max(y)+0.5) %>% + ungroup() %>% + select(Brick, brick_id, xmin, xmax, ymin, ymax, Lego_color, Lego_name) + +ggplot(l_img5) + + geom_rect(aes(xmin=xmin, xmax=xmax, ymin=-ymin, ymax=-ymax, + fill = Lego_color), color = "#333333")+ + scale_fill_identity() + + geom_point(data = l_img2, aes(x=x2, y=-y2), + color = "#666666", alpha = 0.2, shape = 1, size = 3) + + coord_fixed(expand = FALSE) + + theme_minimal()+ + theme(panel.background = element_rect(fill = "#999999"), + axis.title.x = element_blank(), + axis.text.x = element_blank(), + axis.title.y = element_blank(), + axis.text.y = element_blank()) + +#Piece counts! +pieces <- l_img5 %>% + select(Brick, brick_id, Lego_name, Lego_color) %>% + distinct() %>% + separate(Brick, c("g", "gn", "size", "gi")) %>% + select(-g, -gn, -gi) %>% + mutate(size1 = as.numeric(substr(size, 2, 2)), + size2 = as.numeric(substr(size, 4, 4))) %>% + mutate(Brick_size = ifelse(size1>size1, paste(size1, "x", size2), paste(size2, "x" , size1))) %>% + count(Brick_size, Lego_name) %>% + arrange(desc(Brick_size), desc(n)) + +sum(pieces$n) diff --git a/Colors/2016-LEGO-color-palette.pdf b/Colors/2016-LEGO-color-palette.pdf new file mode 100644 index 0000000..472b8e7 Binary files /dev/null and b/Colors/2016-LEGO-color-palette.pdf differ diff --git a/Colors/Colors_Master.xlsx b/Colors/Colors_Master.xlsx new file mode 100644 index 0000000..05085cc Binary files /dev/null and b/Colors/Colors_Master.xlsx differ diff --git a/Colors/Lego_Colors.csv b/Colors/Lego_Colors.csv new file mode 100644 index 0000000..35ee3aa --- /dev/null +++ b/Colors/Lego_Colors.csv @@ -0,0 +1,128 @@ +LEGONo,Color,Sample,R,G,B,c_Palette2016,c_Transparent,c_Glow,c_Metallic,t_Classic,t_Friends,w_Classic +1,White,,242,243,242,TRUE,FALSE,FALSE,FALSE,TRUE,,1.5 +5,Brick yellow,,215,197,153,TRUE,FALSE,FALSE,FALSE,,, +18,Nougat,,204,142,104,TRUE,FALSE,FALSE,FALSE,,, +21,Bright red,,196,40,27,TRUE,FALSE,FALSE,FALSE,TRUE,,2 +23,Bright blue,,13,105,171,TRUE,FALSE,FALSE,FALSE,TRUE,,2 +24,Bright yellow,,245,205,47,TRUE,FALSE,FALSE,FALSE,TRUE,,2 +26,Black,,27,42,52,TRUE,FALSE,FALSE,FALSE,TRUE,,1.5 +28,Dark green,,40,127,70,TRUE,FALSE,FALSE,FALSE,,, +37,Bright green,,75,151,74,TRUE,FALSE,FALSE,FALSE,TRUE,,1.5 +38,Dark orange,,160,95,52,TRUE,FALSE,FALSE,FALSE,TRUE,,1 +40,Transparent,,236,236,236,TRUE,TRUE,FALSE,FALSE,,, +41,Tr. Red,,205,84,75,TRUE,TRUE,FALSE,FALSE,,, +42,Tr. Lg blue,,193,223,240,TRUE,TRUE,FALSE,FALSE,,, +43,Tr. Blue,,123,182,232,TRUE,TRUE,FALSE,FALSE,,, +44,Tr. Yellow,,247,241,141,TRUE,TRUE,FALSE,FALSE,,, +47,Tr. Flu. Reddish orange,,217,133,108,TRUE,TRUE,FALSE,FALSE,,, +48,Tr. Green,,132,182,141,TRUE,TRUE,FALSE,FALSE,,, +49,Tr. Flu. Green,,248,241,132,TRUE,TRUE,FALSE,FALSE,,, +102,Medium blue,,110,153,201,TRUE,FALSE,FALSE,FALSE,,, +106,Bright orange,,218,133,64,TRUE,FALSE,FALSE,FALSE,TRUE,,1 +111,Tr. Brown,,191,183,177,TRUE,TRUE,FALSE,FALSE,,, +113,Tr. Medi. reddish violet,,228,173,200,TRUE,TRUE,FALSE,FALSE,,, +113,Tr. Medium Violet,,253,142,207,TRUE,TRUE,FALSE,FALSE,,TRUE, +119,Br. yellowish green,,164,189,70,TRUE,FALSE,FALSE,FALSE,TRUE,,1 +124,Bright reddish violet,,146,57,120,TRUE,FALSE,FALSE,FALSE,,TRUE, +126,Tr. Bright bluish violet,,165,165,203,TRUE,TRUE,FALSE,FALSE,,TRUE, +135,Sand blue,,116,134,156,TRUE,FALSE,FALSE,FALSE,,, +138,Sand yellow,,149,138,115,TRUE,FALSE,FALSE,FALSE,,, +140,Earth blue,,32,58,86,TRUE,FALSE,FALSE,FALSE,,, +141,Earth green,,39,70,44,TRUE,FALSE,FALSE,FALSE,,, +143,Tr. Flu. Blue,,207,226,247,TRUE,TRUE,FALSE,FALSE,,TRUE, +151,Sand green,,120,144,129,TRUE,FALSE,FALSE,FALSE,,, +154,Dark red,,123,46,47,TRUE,FALSE,FALSE,FALSE,,, +191,Flame yellowish orange,,232,171,45,TRUE,FALSE,FALSE,FALSE,,TRUE, +192,Reddish brown,,105,64,39,TRUE,FALSE,FALSE,FALSE,,, +194,Medium stone grey,,163,162,164,TRUE,FALSE,FALSE,FALSE,,, +199,Dark stone grey,,99,95,97,TRUE,FALSE,FALSE,FALSE,,, +221,Bright purple,,205,98,152,TRUE,FALSE,FALSE,FALSE,,TRUE, +222,Light purple,,228,173,200,TRUE,FALSE,FALSE,FALSE,,TRUE, +226,Cool yellow,,253,234,140,TRUE,FALSE,FALSE,FALSE,,TRUE, +268,Medium lilac,,51,0,114,TRUE,FALSE,FALSE,FALSE,,, +283,Light Nougat,,252,200,155,TRUE,FALSE,FALSE,FALSE,,, +297,Warm Gold,,170,127,46,TRUE,FALSE,FALSE,TRUE,,, +308,Dark brown,,49,38,29,TRUE,FALSE,FALSE,FALSE,,, +311,Tr. Bright Green,,175,210,70,TRUE,TRUE,FALSE,FALSE,,, +312,Medium Nougat,,170,125,85,TRUE,FALSE,FALSE,FALSE,,, +315,Silver Metallic,,140,140,140,TRUE,FALSE,FALSE,TRUE,,, +316,Titanium Metallic,,62,60,57,TRUE,FALSE,FALSE,TRUE,,, +321,Dark Azur,,51,55,198,TRUE,FALSE,FALSE,FALSE,,, +322,Medium Azur,,113,197,232,TRUE,FALSE,FALSE,FALSE,,TRUE, +323,Aqua,,185,220,210,TRUE,FALSE,FALSE,FALSE,,, +324,Med. Lavendar,,160,94,181,TRUE,FALSE,FALSE,FALSE,,, +325,Lavendar,,202,162,221,TRUE,FALSE,FALSE,FALSE,,, +326,Spring Yellowish Green,,212,235,142,TRUE,FALSE,FALSE,FALSE,,TRUE, +329,White Glow,,242,243,242,TRUE,FALSE,TRUE,FALSE,,, +330,Olive Green,,115,123,76,TRUE,FALSE,FALSE,FALSE,,, +2,Grey,,161,165,162,FALSE,FALSE,FALSE,FALSE,,, +3,Light yellow,,249,233,153,FALSE,FALSE,FALSE,FALSE,,, +6,Light green,,194,218,184,FALSE,FALSE,FALSE,FALSE,,, +9,Light reddish violet,,232,186,199,FALSE,FALSE,FALSE,FALSE,,, +12,Light orange brown,,203,132,66,FALSE,FALSE,FALSE,FALSE,,, +22,Med. reddish violet,,196,112,160,FALSE,FALSE,FALSE,FALSE,,, +25,Earth orange,,98,71,50,FALSE,FALSE,FALSE,FALSE,,, +27,Dark grey,,109,110,108,FALSE,FALSE,FALSE,FALSE,,, +29,Medium green,,161,196,139,FALSE,FALSE,FALSE,FALSE,,, +36,Lig. Yellowich orange,,243,207,155,FALSE,FALSE,FALSE,FALSE,,, +39,Light bluish violet,,193,202,222,FALSE,FALSE,FALSE,FALSE,,, +45,Light blue,,180,210,227,FALSE,FALSE,FALSE,FALSE,,, +50,Phosph. White,,236,232,222,FALSE,FALSE,FALSE,FALSE,,, +100,Light red,,238,196,182,FALSE,FALSE,FALSE,FALSE,,, +101,Medium red,,218,134,121,FALSE,FALSE,FALSE,FALSE,,, +103,Light grey,,199,193,183,FALSE,FALSE,FALSE,FALSE,,, +104,Bright violet,,107,50,123,FALSE,FALSE,FALSE,FALSE,,, +105,Br. yellowish orange,,226,155,63,FALSE,FALSE,FALSE,FALSE,,, +107,Bright bluish green,,0,143,155,FALSE,FALSE,FALSE,FALSE,,, +108,Earth yellow,,104,92,67,FALSE,FALSE,FALSE,FALSE,,, +110,Bright bluish violet,,67,84,147,FALSE,FALSE,FALSE,FALSE,,, +112,Medium bluish violet,,104,116,172,FALSE,FALSE,FALSE,FALSE,,, +115,Med. yellowish green,,199,210,60,FALSE,FALSE,FALSE,FALSE,,, +116,Med. bluish green,,85,165,175,FALSE,FALSE,FALSE,FALSE,,, +118,Light bluish green,,183,215,213,FALSE,FALSE,FALSE,FALSE,,, +120,Lig. yellowish green,,217,228,167,FALSE,FALSE,FALSE,FALSE,,, +121,Med. yellowish orange,,231,172,88,FALSE,FALSE,FALSE,FALSE,,, +123,Br. reddish orange,,211,111,76,FALSE,FALSE,FALSE,FALSE,,, +125,Light orange,,234,184,145,FALSE,FALSE,FALSE,FALSE,,, +127,Gold,,220,188,129,FALSE,FALSE,FALSE,FALSE,,, +128,Dark nougat,,174,122,89,FALSE,FALSE,FALSE,FALSE,,, +131,Silver,,156,163,168,FALSE,FALSE,FALSE,FALSE,,, +133,Neon orange,,213,115,61,FALSE,FALSE,FALSE,FALSE,,, +134,Neon green,,216,221,86,FALSE,FALSE,FALSE,FALSE,,, +136,Sand violet,,135,124,144,FALSE,FALSE,FALSE,FALSE,,, +137,Medium orange,,224,152,100,FALSE,FALSE,FALSE,FALSE,,, +145,Sand blue metallic,,121,136,161,FALSE,FALSE,FALSE,FALSE,,, +146,Sand violet metallic,,149,142,163,FALSE,FALSE,FALSE,FALSE,,, +147,Sand yellow metallic,,147,135,103,FALSE,FALSE,FALSE,FALSE,,, +148,Dark grey metallic,,87,88,87,FALSE,FALSE,FALSE,FALSE,,, +149,Black metallic,,22,29,50,FALSE,FALSE,FALSE,FALSE,,, +150,Light grey metallic,,171,173,172,FALSE,FALSE,FALSE,FALSE,,, +153,Sand red,,149,121,118,FALSE,FALSE,FALSE,FALSE,,, +157,Tr. Flu. Yellow,,255,246,123,FALSE,FALSE,FALSE,FALSE,,, +158,Tr. Flu. Red,,225,164,194,FALSE,FALSE,FALSE,FALSE,,, +168,Gun metallic,,117,108,98,FALSE,FALSE,FALSE,FALSE,,, +176,Red flip/flop,,151,105,91,FALSE,FALSE,FALSE,FALSE,,, +178,Yellow flip/flop,,180,132,85,FALSE,FALSE,FALSE,FALSE,,, +179,Silver flip/flop,,137,135,136,FALSE,FALSE,FALSE,FALSE,,, +180,Curry,,215,169,75,FALSE,FALSE,FALSE,FALSE,,, +190,Fire Yellow,,249,214,46,FALSE,FALSE,FALSE,FALSE,,, +193,Flame reddish orange,,207,96,36,FALSE,FALSE,FALSE,FALSE,,, +195,Royal blue,,70,103,164,FALSE,FALSE,FALSE,FALSE,,, +196,Dark Royal blue,,35,71,139,FALSE,FALSE,FALSE,FALSE,,, +198,Bright reddish lilac,,142,66,133,FALSE,FALSE,FALSE,FALSE,,, +200,Lemon metalic,,130,138,93,FALSE,FALSE,FALSE,FALSE,,, +208,Light stone grey,,229,228,222,FALSE,FALSE,FALSE,FALSE,,, +209,Dark Curry,,176,142,68,FALSE,FALSE,FALSE,FALSE,,, +210,Faded green,,112,149,120,FALSE,FALSE,FALSE,FALSE,,, +211,Turquoise,,121,181,181,FALSE,FALSE,FALSE,FALSE,,, +212,Light Royal blue,,159,195,233,TRUE,FALSE,FALSE,FALSE,,TRUE, +213,Medium Royal blue,,108,129,183,FALSE,FALSE,FALSE,FALSE,,, +216,Rust,,143,76,42,FALSE,FALSE,FALSE,FALSE,,, +217,Brown,,124,92,69,FALSE,FALSE,FALSE,FALSE,,, +218,Reddish lilac,,150,112,159,FALSE,FALSE,FALSE,FALSE,,, +219,Lilac,,107,98,155,FALSE,FALSE,FALSE,FALSE,,, +220,Light lilac,,167,169,206,FALSE,FALSE,FALSE,FALSE,,, +223,Light pink,,220,144,149,FALSE,FALSE,FALSE,FALSE,,, +224,Light brick yellow,,240,213,160,FALSE,FALSE,FALSE,FALSE,,, +225,Warm yellowish orange,,235,184,127,FALSE,FALSE,FALSE,FALSE,,, +232,Dove blue,,125,187,221,FALSE,FALSE,FALSE,FALSE,,, diff --git a/Images/AgeOfReptiles.jpg b/Images/AgeOfReptiles.jpg new file mode 100644 index 0000000..331ae85 Binary files /dev/null and b/Images/AgeOfReptiles.jpg differ diff --git a/Images/anthonyryan.JPG b/Images/anthonyryan.JPG new file mode 100644 index 0000000..098c77c Binary files /dev/null and b/Images/anthonyryan.JPG differ diff --git a/Images/bobcatflower.JPG b/Images/bobcatflower.JPG new file mode 100644 index 0000000..c9dd3dd Binary files /dev/null and b/Images/bobcatflower.JPG differ diff --git a/Images/henry.JPG b/Images/henry.JPG new file mode 100644 index 0000000..2d87587 Binary files /dev/null and b/Images/henry.JPG differ diff --git a/Images/ryanbob.JPG b/Images/ryanbob.JPG new file mode 100644 index 0000000..0223c4e Binary files /dev/null and b/Images/ryanbob.JPG differ diff --git a/Images/selfie.jpg b/Images/selfie.jpg new file mode 100644 index 0000000..b3cb217 Binary files /dev/null and b/Images/selfie.jpg differ diff --git a/Images/selfiecher.JPG b/Images/selfiecher.JPG new file mode 100644 index 0000000..e3fce0c Binary files /dev/null and b/Images/selfiecher.JPG differ