find_color_spread: Find a spread of colors with minimum distance between them

find_color_spreadR Documentation

Find a spread of colors with minimum distance between them

Description

Find a spread of colors with minimum distance between them

Usage

find_color_spread(
  x,
  n = 2,
  min_distance = 11.5,
  step_distance = 0,
  method = "cie2000",
  use_white = "F5",
  byCols = c("-met_n", "-d", "-found_n"),
  first_only = TRUE,
  verbose = FALSE,
  ...
)

Arguments

x

character vector of colors

n

integer minimum number of colors

min_distance

numeric minimum distance required between colors.

step_distance

numeric default 0, when non-zero the min_distance is iterated until the min_distance criteria are met for at least n colors.

method

character distance method, default 'cie2000'.

use_white

character white reference, default 'F5'.

byCols

character with optional column sorting, used to prioritize results when first_only=FALSE. The columns are sorted as follows:

  • '-met_n' - decreasing filter of whether the n threshold was met

  • '-d' - decreasing minimum distance in each color set

  • '-found_n' - decreasing number of colors that met the criteria

first_only

logical default FALSE, whether to return only the first successful color combination meeting the criteria for min_distance and n.

  • When first_only=FALSE it will exhaustively determine all possible combinations of colors, which is time consuming for larger n values, even when n=6. However, this approach is able to find the most different combination of colors from x, based upon byCols column sorting.

...

additional arguments are passed to color_distance().

Details

Intended to be called internally by add_colors(), this function takes a vector of colors x, and finds a subset of at least n colors that each have color distance min_distance using the method and use_white white reference.

It is intended to solve the problem when M colors are available, very close to a neighboring color, but a subset N colors are requested which each have at least min_distance from each other.

This function is currently not very optimized, although it does avoid repeating combinations of color tests.

It currently iterates each color, then each secondary color with at least min_distance, and so on, until at least n colors in a set have at least min_distance distance between them. It then runs all combinations and sorts for the set with the highest minimum distance, thereby the "most distinctive subset".

Examples

find_color_spread(colorspace::rainbow_hcl(12), n=5, min_distance=20, step_distance=-1, first_only=TRUE)
find_color_spread(colorspace::rainbow_hcl(30), n=12, min_distance=20, step_distance=-1, first_only=TRUE)


jmw86069/colorjam documentation built on June 10, 2025, 12:02 p.m.