legocolor: Color mapping

Description Usage Arguments Details Value Examples

Description

Map between hex and color names.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
hex_to_color(x, approx = TRUE, prefix = "~")

hex_to_legocolor(x, def = c("bricklink", "ldraw", "tlg", "peeron"),
  approx = TRUE, prefix = "~", material = NULL, retired = FALSE)

legocolor_to_hex(x, def = c("bricklink", "ldraw", "tlg", "peeron"))

view_legopal(x, def = c("bricklink", "ldraw", "tlg", "peeron"),
  approx = TRUE, prefix = "~", material = NULL, retired = FALSE,
  show_labels = FALSE, label_size = 1)

Arguments

x

character, hex color or color name. May be a vector. See details.

approx

logical, find and return closest color name when an exact match does not exist.

prefix

character, prefix for approximate color matches.

def

character, the Lego color name definition to apply: "bricklink", "ldraw", "tlg" or "peeron". See details.

material

logical, consider only the subset of Lego color names by filtering on levels of legocolors$material. By default, all are considered.

retired

logical, filter out Lego colors that are retired, defaults to FALSE.

show_labels

logical, show color name and hex value in palette preview.

label_size

numeric, text size.

Details

These functions map between hex color codes and color names. Convert any color palette to a palette of the most closely matched official Lego colors.

The two complimentary Lego color mapping functions are hex_to_legocolors and legocolors_to_hex. The first takes a hex color string and converts to the nearest valid Lego color name by Euclidean distance. The second takes a valid Lego color name and converts to hex.

Valid Lego color names are determined by the definition, def. The four options provide different name sets for existing Lego colors. The default is def = "bricklink". BrickLink is the default naming convention source for several reasons:

Essentially, when converting an image or 3D model in R into a set of Lego parts that must be custom ordered to construct your design, BrickLink is the clear best option for obtaining the most complete set of parts required and at the lowest price.

If approx = FALSE, an unmatched element returns NA.

hex_to_color is provided for general convenience. It converts hex color codes to the familiar R color names. Consistent with the Lego-specific mapping functions, by default approx = TRUE returns the nearest color name based on Euclidean distance. prefix allows for prepending an identifier to the beginning of any color name that a hex color code does not match exactly.

Value

character vector of color names or hex colors

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
hex_to_color(c("#ff0000", "#ff0001"))
hex_to_legocolor("#ff0000")
hex_to_legocolor("#ff0000", material = "solid")
legocolor_to_hex("Red")
hex_to_color(legocolor_to_hex("Red"))

if(interactive()){
  view_legopal(rainbow(9), material = "solid",
               show_labels = TRUE, label_size = 0.7)
}

legocolors documentation built on May 2, 2019, 6:53 a.m.