RGB::colorName

Find names of predefined colors

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

```RGB::colorName(`rgb`, <Exact>)
```

Description

`RGB::colorName([r, g, b])` looks for the predefined color with values closest to `[r, g, b]` and returns its name.

`RGB::colorName([r, g, b], Exact)` looks for a predefined color with values exactly `[r, g, b]` and returns its name.

The `RGB` namespace contains predefined color names, accessible as `RGB::Blue` etc. `RGB::colorName` performs a reverse lookup, finding the name of a color given as RGB values.

Since rather often, colors will stem from calculations with floating-point numbers, no exact matches can be expected in this reverse lookup. Therefore, by default, `RGB::colorName` will perform a "fuzzy" search, returning the predefined color which is closest (in Euclidean distance in RGB space) to the input. Cf. Example 2.

Examples

Example 1

`RGB::colorName` returns the symbolic name of predefined colors:

`RGB::colorName([0, 1, 0])`

`RGB::colorName([0, 1, 0, 0.5])`

Example 2

When performing calculations on color values, the results will rarely be exact, even if the unavoidable round-off errors are too small to be displayed on the screen:

```a := RGB::Olive; b := RGB::fromHSV(RGB::toHSV(RGB::Olive))```

`bool(a = b)`

Therefore, `RGB::colorName` by default searches in a "fuzzy" fashion:

```RGB::colorName(a); RGB::colorName(b)```

In cases where this is undesirable, the option `Exact` can be used to switch to exact searching:

```RGB::colorName(a, Exact); RGB::colorName(b, Exact)```

The predefined color names do not fill RGB space uniformly, therefore, the color found by `RGB::colorName` may be quite different from the one entered. The following plot shows the predefined colors in RGB space:

```plot(plot::Scene3d( plot::PointList3d([c.[c] \$ c in RGB::ColorList]), ZXRatio = 1, BackgroundStyle = TopBottom, BackgroundColor = RGB::Grey, BackgroundColor2 = RGB::White, Margin=0))```

Parameters

 `rgb` An RGB or RGBa color specification: A list of three or four real numbers in the interval .

Options

 `Exact` Only return an exact match, FAIL if none exists.

Return Values

If a color was found, `RGB::colorName` returns an expression of the form `RGB::Name` or `RGB::Name.[a]`. If given `Exact` and no match was found, `FAIL` is returned. If given symbolic input parameters, an unevaluated call is returned.