Last active
September 13, 2016 09:48
-
-
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
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
| 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