Read benjamin moore list of colors with HEX code from colornerd
Code
suppressMessages(library(tidyverse))# Install and load the jsonlite packageif (!require(jsonlite)) install.packages("jsonlite")
Loading required package: jsonlite
Attaching package: 'jsonlite'
The following object is masked from 'package:purrr':
flatten
Code
suppressMessages(library(jsonlite))# Define the URL of the JSON file#url <- "https://raw.githubusercontent.com/wesbos/benjamin-moore-css/main/colors.json"url <-"https://raw.githubusercontent.com/hakyim/benjamin-moore-css/main/colors.json"# Read the JSON file from the URLdata <-fromJSON(url) %>%as_tibble()# Function to convert hex to RGBhex_to_rgb <-function(hex) { hex <-paste0("#", hex) # Ensure the hex value has a '#' prefix rgb <-col2rgb(hex)list(r = rgb[1, 1], g = rgb[2, 1], b = rgb[3, 1])}# Function to calculate LRV from RGBcalculate_lrv <-function(hex) { rgb <-hex_to_rgb(hex) lrv_trucho <- (0.2126* rgb$r +0.7152* rgb$g +0.0722* rgb$b) /255*100return(lrv_trucho)}# Calculate LRV for each colordata <- data %>%mutate(lrv_trucho =map_dbl(hex, calculate_lrv))# show properties of my selected colorsdata %>%filter(name %in%c("Classic Gray","Gray Owl","Abalone")) %>%select(name, hex, lrv_trucho, number, family) %>%arrange(name)
---title: benjamin moore colorsauthor: Haky Imdate: 2020-01-01---Read benjamin moore list of colors with HEX code from colornerd```{r read benjamin moore color json}suppressMessages(library(tidyverse))# Install and load the jsonlite packageif (!require(jsonlite)) install.packages("jsonlite")suppressMessages(library(jsonlite))# Define the URL of the JSON file#url <- "https://raw.githubusercontent.com/wesbos/benjamin-moore-css/main/colors.json"url <-"https://raw.githubusercontent.com/hakyim/benjamin-moore-css/main/colors.json"# Read the JSON file from the URLdata <-fromJSON(url) %>%as_tibble()# Function to convert hex to RGBhex_to_rgb <-function(hex) { hex <-paste0("#", hex) # Ensure the hex value has a '#' prefix rgb <-col2rgb(hex)list(r = rgb[1, 1], g = rgb[2, 1], b = rgb[3, 1])}# Function to calculate LRV from RGBcalculate_lrv <-function(hex) { rgb <-hex_to_rgb(hex) lrv_trucho <- (0.2126* rgb$r +0.7152* rgb$g +0.0722* rgb$b) /255*100return(lrv_trucho)}# Calculate LRV for each colordata <- data %>%mutate(lrv_trucho =map_dbl(hex, calculate_lrv))# show properties of my selected colorsdata %>%filter(name %in%c("Classic Gray","Gray Owl","Abalone")) %>%select(name, hex, lrv_trucho, number, family) %>%arrange(name)```