Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while using farver::encode_colour #48

Closed
ericmelse opened this issue Jul 11, 2024 · 1 comment
Closed

Error while using farver::encode_colour #48

ericmelse opened this issue Jul 11, 2024 · 1 comment

Comments

@ericmelse
Copy link

ericmelse commented Jul 11, 2024

Dear Thomas,

With great interest I am exploring your fine package farver but I have issues while using farver::encode_colour
My objective is to calculate color codes between color spaces. Here I get a range of colours in CIELAB space using:

lab_a_L50 <- farver::encode_colour(
  cbind(l=50,
        a=c(-100, -90, -80, -70, -60, -50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100),
        b=0), from="lab")
lab_a_L50
# [1] "#009775" "#009575" "#009375" "#009175" "#008E75" "#008B76" "#008876" "#2A8476" "#4C8076" "#647C77" "#777777" "#887177" "#986B78" "#A66378" "#B45A78" "#C24F79"
# [17] "#CF4179" "#DC2C7A" "#E8007A" "#F5007B" "#FF007B"

That works just fine and next I create a figure with the result data, like:
CIELAB_L50a
With the above I want to show (graded) colors along the CIELAB a-axis with the b-axis value of each color set to 0 (neutral point) at the lightness level set to 50.

But, now I want to do the same for the CIELAB b-axis using this command:

lab_b_L50 <- farver::encode_colour(
  cbind(l=50,
        a=0,
        b=c(-100, -90, -80, -70, -60, -50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100), from="lab")
lab_b_L50

As such the command code runs without any complaint, but using lab_b_L50 after that results in the error message:

Error: unexpected symbol in:
"        b=c(-100, -90, -80, -70, -60, -50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100), from="lab")
lab_b_L50"

I also tried:

lab_b_L50 <- farver::encode_colour(
  cbind(l=50,
       a=c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
       b=c(-100, -90, -80, -70, -60, -50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100), from="lab")
lab_b_L50

which produces the same error message.
Note that this command code (for the a-axis):

lab_a_L50 <- farver::encode_colour(
  cbind(l=50,
        a=c(-100, -90, -80, -70, -60, -50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100),
        b=c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), from="lab")
lab_a_L50

also produces the same error message.

So, maybe I am confused about how to set values for the a and b axis (dimension) in CIELAB but so far I found only one example in the documention that produces the expected result (which I used succesfully for the first example above).

Time permitting, I really apreciate your helping hand how to properly set such parameters for CIELAB (and OKLAB).

Best,
Eric

@ericmelse
Copy link
Author

Dear Thomas,
While exercising with your farver package , I also used the r-wizard of the chatgpt website and that resulted in the correct code:

lab_b_L50 <- farver::encode_colour(
  cbind(l=50,
        a=0,
        b=c(-100, -90, -80, -70, -60, -50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100)), from="lab")
lab_b_L50

That works just fine and next I create a figure with the result data, like:
lab_b_L50
So, my little tricky error was that I did not use a second closing bracket that is required )), from="lab")

For those interested in calculating the CIELAB AB plane at a given L-value, this is code how to produce that:

# Create a plane of colors for the CIELAB color space using the farver package
# Define the range and step size for a and b
a_range <- seq(-100, 100, by = 10)
b_range <- seq(-100, 100, by = 10)

# Create a grid of a and b values
lab_grid <- expand.grid(a = a_range, b = b_range)

# Define the constant lightness (L) value
lab_L <- 50

# Create the colors using the farver package
lab_AxB_L50_10 <- farver::encode_colour(
  cbind(
    l = lab_L,
    a = lab_grid$a,
    b = lab_grid$b
  ), from = "lab"
)

Which results in:
lab_AxB_L50_10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant