Use these functions to create palette-like functions, but with different inputs or outputs.

Use pth_pal_input_discrete() to create a function that takes an integer as input, rather than a numeric vector. In other words, it takes a continuous-palette function and returns a discrete-palette function.

Use pth_pal_output_hex() to create a function that returns hex-codes, rather than a matrix. In addition to converting to hex-codes, the returned will "rescue" out-of-gamut colors by reducing the chroma of such colors to bring them inside the gamut.

Note that these functions do not require a pth_palette function, nor does it return one. This means that these functions take you "off the boat". Accordingly, you should consider using them as final steps.

pth_pal_input_discrete(pal)

pth_pal_output_hex(pal)

Arguments

pal

function palette-like function, returns a color

Value

pth_pal_input_discrete()

function that takes an integer as an input, returns that many colors.

pth_pal_output_hex()

function that returns hex-codes.

Examples

  hex_blue <- c("#e2e2e2", "#9cbaee", "#3c79c0")

  pal_blue <- pth_new_palette_hex(hex_blue)
  pal_blue_discrete <- pth_pal_input_discrete(pal_blue)

  pal_blue_hex <- pth_pal_output_hex(pal_blue)
  pal_blue_discrete_hex <- pth_pal_input_discrete(pal_blue_hex)

  # returns matrix
  pal_blue(seq(0, 1, by = 0.25))
#>            L*            u*            v*
#> [1,] 89.88369 -1.804449e-05  1.200872e-05
#> [2,] 83.74033 -9.758484e+00 -2.685621e+01
#> [3,] 75.04937 -1.699302e+01 -4.679061e+01
#> [4,] 63.81080 -2.170364e+01 -5.980318e+01
#> [5,] 50.02462 -2.389032e+01 -6.589392e+01
#> attr(,"class")
#> [1] "pth_cieluv" "pth_mat"   
#> attr(,"whitepoint")
#> [1]  95.047 100.000 108.883

  # takes an integer input, returns matrix
  pal_blue_discrete(5)
#>            L*            u*            v*
#> [1,] 89.88369 -1.804449e-05  1.200872e-05
#> [2,] 83.74033 -9.758484e+00 -2.685621e+01
#> [3,] 75.04937 -1.699302e+01 -4.679061e+01
#> [4,] 63.81080 -2.170364e+01 -5.980318e+01
#> [5,] 50.02462 -2.389032e+01 -6.589392e+01
#> attr(,"class")
#> [1] "pth_cieluv" "pth_mat"   
#> attr(,"whitepoint")
#> [1]  95.047 100.000 108.883

  # returns hex-codes
  pal_blue_hex(seq(0, 1, by = 0.25))
#> [1] "#e2e2e2" "#c2d1f0" "#9cbaee" "#709cdd" "#3c79c0"
#> attr(,"class")
#> [1] "pth_hex"

  # takes an integer input, returns hex-codes
  pal_blue_discrete_hex(5)
#> [1] "#e2e2e2" "#c2d1f0" "#9cbaee" "#709cdd" "#3c79c0"
#> attr(,"class")
#> [1] "pth_hex"