MyNixOS website logo
Description

Official Lego Color Palettes.

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/>).

legocolors

Author:Matthew LeonawiczORCID logo
License:MIT

Project Status: Active – The project has reached a stable, usablestate and is being activelydeveloped. Travis buildstatus AppVeyor buildstatus Codecov testcoverage

CRANstatus CRANdownloads GithubStars

Donate

legocolors provides a dataset containing several Lego color naming conventions established by various popular sources. It also provides functions for mapping between these color naming conventions as well as between Lego color names, hex colors, and R color names.

By default, nearest colors are computed based on distance in RGB space when an exact match is not found. This behavior supports the purpose of exchanging arbitrary colors for known Lego colors when the goal is to actually acquire and build something out of Lego parts. This focus is also one of the reasons legocolors uses BrickLink color names as the default naming convention. See ?legocolor for details.

Installation

Install the CRAN release of legocolors with

install.packages("legocolors")

Install the development version from GitHub with

# install.packages("remotes")
remotes::install_github("leonawicz/legocolors")

Palette conversions

The key helper functions are hex_to_legocolor and legocolor_to_hex. hex_to_color is also provided for general convenience.

library(legocolors)
hex_to_color(c("#ff0000", "#ff0001"))
#> [1] "red"  "~red"
hex_to_legocolor("#ff0000")
#> [1] "~Trans-Red"
hex_to_legocolor("#ff0000", material = "solid")
#> [1] "~Red"
legocolor_to_hex("Red")
#> [1] "#B40000"
hex_to_color(legocolor_to_hex("Red"))
#> [1] "~red3"

x <- topo.colors(10)
hex_to_legocolor(x)
#>  [1] "~Dark Purple"              "~Blue"                     "~Trans-Dark Blue"          "~Medium Azure"             "~Bright Green"             "~Lime"                    
#>  [7] "~Glitter Trans-Neon Green" "~Trans-Yellow"             "~Trans-Neon Green"         "~Light Nougat"
hex_to_legocolor(x, material = "solid")
#>  [1] "~Dark Purple"         "~Blue"                "~Dark Azure"          "~Medium Azure"        "~Bright Green"        "~Lime"                "~Yellow"             
#>  [8] "~Yellow"              "~Bright Light Yellow" "~Light Nougat"
hex_to_legocolor(x, def = "tlg", material = "solid")
#>  [1] "~Medium Lilac"           "~Bright Blue"            "~Dark Azur"              "~Medium Azur"            "~Bright Green"           "~Bright Yellowish Green"
#>  [7] "~Bright Yellow"          "~Bright Yellow"          "~Cool Yellow"            "~Light Nougat"

While different sets of Lego colors are organized by material type, e.g., solid colors, semi-transparent colors, etc., these palettes are not useful for plotting data. The greatest value comes from converting useful color palettes to those comprised of existing Lego colors while still keeping as close to the original palette as possible.

Palette preview

The view_legopal function can be used to quickly see a Lego color palette. It can plot a named material palette, but like the functions above, it can also display a converted palette if given an arbitrary vector of hex color values.

view_legopal("solid")

r <- rainbow(9)
r
#> [1] "#FF0000" "#FFAA00" "#AAFF00" "#00FF00" "#00FFAA" "#00AAFF" "#0000FF" "#AA00FF" "#FF00AA"

view_legopal(r, material = "solid", show_labels = TRUE, label_size = 0.7)

Recommended colors

Dealing with

  • Available colors for generic bricks and plates but prohibitively expensive.
  • Available colors for generic bricks and plates but with low supply.
  • Colors used only for exotic/specialty parts (not available for bricks and plates).

Filtering to a decent set of Lego colors that are relatively easy to acquire online at BrickLink.com for simple brick and/or plate parts, and relatively affordable, is largely the responsibility of the user. There is a recommended column in the legocolors dataset. However, a human-derived recommendation column would be better (feel free to submit a PR if you’d like to improve the package).

In the previous version of legocolors, brick- and plate- specific data, excluding more exotic parts, was scraped from the website catalog, but this has become too difficult to do reliably. For now, you will have to use your personal Lego knowledge to filter out irrelevant or problematic colors from the complete official set. This is worth considering because even though BrickLink consistently offers the widest selection and greatest quantity at the lowest price, supply and demand leads to some parts in some colors being prohibitively expensive to acquire in quantity. When determining what colors you wish to use to build a physical model, you will save an incredible amount of money if you can accept limiting your palette to the most common Lego colors.


Please note that the legocolors project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Metadata

Version

0.3.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows