Created
August 13, 2021 00:23
-
-
Save obrl-soil/2c34f2254ab4feaca99f13a1aac619be to your computer and use it in GitHub Desktop.
Munsell colour notation to RGB and hex values
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
library(munsellinterpol) | |
library(dplyr) | |
library(tibble) | |
library(purrr) | |
rgb2hex <- function(r,g,b) rgb(r, g, b, maxColorValue = 255) | |
munsells <- tribble(~ID, ~HUE, ~VALUE, ~CHROMA, | |
1, '10YR', '3', '6', | |
2, '5Y', '5', '1', | |
3, 'N', '2', '0', | |
4, '7.5YR', '8', '7') %>% | |
# note the formatting: | |
mutate(MCOL = paste0(HUE, ' ', VALUE, '/', CHROMA)) | |
translated <- | |
purrr::map_dfr(munsells$MCOL, function(i) { | |
x <- munsellinterpol::MunsellToRGB(i) | |
# just keep what's needed from function output: | |
data.frame("R" = round(x$RGB[1]), | |
"G" = round(x$RGB[2]), | |
"B" = round(x$RGB[3]) | |
) | |
}) %>% | |
mutate(HEX = rgb2hex(R, G, B)) %>% | |
cbind(munsells, .) | |
# optional | |
hues::swatch(translated$HEX) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment