Created
April 14, 2018 21:30
-
-
Save lukereding/a970346a3cf86484cd7608a4ca2e4181 to your computer and use it in GitHub Desktop.
Code to reproduce the flyer for john and I's graduation party
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
# edited from https://github.com/aschinchon/travelling-salesman-portrait/blob/master/frankenstein_TSP.R | |
library(imager) | |
library(dplyr) | |
library(ggplot2) | |
library(scales) | |
library(TSP) | |
urlfile <- "https://www.dropbox.com/s/4td7zbqohyw0f3g/creepy.jpg?dl=0" | |
file <- "creepy.jpg" | |
if (!file.exists(file)) download.file(urlfile, destfile = file, mode = "wb") | |
# Load, convert to grayscale, filter image (to convert it to bw) and sample | |
load.image(file) %>% | |
grayscale() %>% | |
threshold("25%") %>% | |
as.cimg() %>% | |
as.data.frame() %>% | |
sample_n(as.integer(nrow(.) * 0.006), weight = (1 - value)) %>% | |
select(x, y) -> data | |
# Compute distances and solve TSP (it may take a minute) | |
as.TSP(dist(data)) %>% | |
solve_TSP(method = "arbitrary_insertion") %>% | |
as.integer() -> solution | |
# Create a dataframe with the output of TSP | |
data.frame(id = solution) %>% | |
mutate(order = row_number()) -> order | |
# Rearrange the original points according the TSP output | |
data %>% | |
mutate(id = row_number()) %>% | |
inner_join(order, by = "id") %>% | |
arrange(order) %>% | |
select(x, y) -> data_to_plot | |
# saveRDS(data_to_plot, "~/Desktop/data_for_poster.Rdata") | |
# data_to_plot <- readRDS("~/Desktop/data_for_poster.Rdata") | |
details <- "Like the unholy fusion of John and Luke below, this party will be not of this world.\n\nHave you been to a party with party favors not of throwaway nicnacs but cone-10 blasted, utilitarian earthenware pottery? \nWhat about a party with a hand-picked boutique playlist sick enough to summon a reunion of the ghosts of 2Pac and Biggie,\nwith some late-2000s prom-memory-evoking head-bangers tossed in for good measure?\nA party with kegs of Adelberts, Dogfish, and artisan brews from John's private collection,\nmeticuously perfected under ever-watchful eyes?\nA party that attracts thickly-cortexed grad students like moths attracted to light for reasons they know not,\nfrom >= five departments across three schools?\n\nOf course you haven't.\n\nWe present a party unlike any other." | |
john <- "Never touched a fish\n\nPublished in top journals\nlike Cell and PNAS\n\nOnce gave a talk via iPhone\n\nmatplotlib\n\n1 advisor -> 2 advisors\n\ngrew an amazing beard\n\npost-doc" | |
luke <- "Had to touch a fish\n\nAnimal Behaviour is a\ngood journal, right?\n\nOnce gave a 50 min talk with 19 slides\n\nggplot2\n\n2 advisors -> 1 advisor\n\neh\n\n\"industry\"" | |
ggplot(data_to_plot, aes(x, y)) + | |
geom_path(size = 0.5) + | |
scale_y_continuous(trans = reverse_trans()) + | |
coord_fixed(xlim = c(-500, 1500), ylim = c(-200, 1800)) + | |
annotate("text", x = -500, y = -200, label = "we're graduating", size = 14, hjust = 0) + | |
annotate("text", x = -500, y = 400, label = details, size = 2, hjust = 0, vjust = 0, lineheight = 0.8) + | |
annotate("text", x = -500, y = 550, label = "when:", fontface = "bold", size = 2, hjust = 0, vjust = 0, lineheight = 0.8) + | |
annotate("text", x = -300, y = 550, label = "20 April @ 7", size = 2, hjust = 0, vjust = 0, lineheight = 0.8) + | |
annotate("text", x = -500, y = 650, label = "where:", fontface = "bold", size = 2, hjust = 0, vjust = 0, lineheight = 0.8) + | |
annotate("text", x = -300, y = 650, label = "109 E 48th St", size = 2, hjust = 0, vjust = 0, lineheight = 0.8) + | |
annotate("text", x = -500, y = 1000, label = john, size = 2, hjust = 0, vjust = 1, lineheight = 1.2) + | |
annotate("text", x = 1550, y = 1000, label = luke, size = 2, hjust = 1, vjust = 1, lineheight = 1.2) + | |
annotate("text", x = 1550, y = 1800, label = "luke", size = 4, hjust = 1, vjust = 1, lineheight = 1.2) + | |
annotate("text", x = -500, y = 1800, label = "john", size = 4, hjust = 0, vjust = 1, lineheight = 1.2) + | |
theme_void() | |
ggsave("~/Desktop/flyer.png", height = 5.5, width = 5.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment