Skip to content

Instantly share code, notes, and snippets.

@cosi1
Last active September 13, 2016 09:48
Show Gist options
  • Save cosi1/58caa09a93d2510a99ec3a8c8e0ac97b to your computer and use it in GitHub Desktop.
Save cosi1/58caa09a93d2510a99ec3a8c8e0ac97b to your computer and use it in GitHub Desktop.
Converts a list of colors in hexadecimal format (#RRGGBB) to a list of PyMOL's `set_color` commands
library(magrittr)
hex_to_rgb = function(color_list) {
mapply(function(clr, i) {
clr %>%
substring(c(2, 4, 6), c(3, 5, 7)) %>%
paste0("0x", .) %>%
strtoi() %>%
`/`(256) %>%
paste(collapse = ",") %>%
sprintf("set_color color_%i, [%s]", i, .)
}, color_list, 1:length(color_list))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment