Title: Official Lego Color Palettes
Version: 0.4.0
Description: Provides a dataset containing several color naming conventions established by multiple sources, along with associated color metadata. The package also provides related helper functions for mapping among the different Lego color naming conventions and between Lego colors, hex colors, and 'R' color names, making it easy to convert any color palette to one based on existing Lego colors while keeping as close to the original color palette as possible. The functions use nearest color matching based on Euclidean distance in RGB space. Naming conventions for color mapping include those from 'BrickLink' (https://www.bricklink.com), 'The Lego Group' (https://www.lego.com), 'LDraw' (https://www.ldraw.org/), and 'Peeron' (http://www.peeron.com/).
License: MIT + file LICENSE
URL: https://github.com/leonawicz/legocolors
BugReports: https://github.com/leonawicz/legocolors/issues
Depends: R (≥ 2.10)
Suggests: testthat, covr
Encoding: UTF-8
Language: en-US
LazyData: true
RoxygenNote: 7.3.2
NeedsCompilation: no
Packaged: 2024-09-11 21:54:12 UTC; Matt
Author: Matthew Leonawicz [aut, cre]
Maintainer: Matthew Leonawicz <rpkgs@pm.me>
Repository: CRAN
Date/Publication: 2024-09-11 22:52:39 UTC

legocolors: Official Lego Color Palettes

Description

logo

Provides a dataset containing several color naming conventions established by multiple sources, along with associated color metadata. The package also provides related helper functions for mapping among the different Lego color naming conventions and between Lego colors, hex colors, and 'R' color names, making it easy to convert any color palette to one based on existing Lego colors while keeping as close to the original color palette as possible. The functions use nearest color matching based on Euclidean distance in RGB space. Naming conventions for color mapping include those from 'BrickLink' (https://www.bricklink.com), 'The Lego Group' (https://www.lego.com), 'LDraw' (https://www.ldraw.org/), and 'Peeron' (http://www.peeron.com/).

Author(s)

Maintainer: Matthew Leonawicz rpkgs@pm.me

See Also

Useful links:


Predefined palettes and palette generators

Description

These functions are analogs to familiar R color palettes but based on Lego colors.

Usage

lc_terrain(n)

lc_topo(n)

lc_heat(n)

Arguments

n

if not provided, return the vector of official Lego colors defining the palette. If provided, return an interpolated palette, which will contain non-Lego colors only if n is greater than the palette definition.

Value

character vector of hex colors

Examples

lc_terrain()
lc_terrain(4)

lc_topo()
lc_heat()

Lego color data.

Description

A data frame containing Lego color data.

Usage

legoCols

Format

A data frame with 12 columns and 167 rows.


Lego color palettes.

Description

A named list of nine Lego color palettes based on legoCols$material. Because these palettes represent a meaningful segmentation of Lego material types, they are not intended to represent useful color palettes for mapping data values to colors.

Usage

legoPals

Format

A named list of nine color palettes.


Color mapping

Description

Map between hex and color names.

Usage

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 legoCols$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

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)
}

mirror server hosted at Truenetwork, Russian Federation.