color_of: Color of an object

Description Usage Arguments Value Methods (by class) Deprecated Note Examples

View source: R/color.of.R

Description

Equivalent RGB color of an object such as a spectrum, wavelength or waveband.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
color_of(x, ...)

## Default S3 method:
color_of(x, ...)

## S3 method for class 'numeric'
color_of(x, type = "CMF", chroma.type = type, ...)

## S3 method for class 'list'
color_of(x, short.names = TRUE, type = "CMF", chroma.type = type, ...)

## S3 method for class 'waveband'
color_of(x, short.names = TRUE, type = "CMF", chroma.type = type, ...)

## S3 method for class 'source_spct'
color_of(x, type = "CMF", chroma.type = type, ...)

## S3 method for class 'source_mspct'
color_of(x, ..., idx = "spct.idx")

colour_of(x, ...)

color(x, ...)

fast_color_of_wl(x, type = "CMF", ...)

fast_color_of_wb(x, type = "CMF", ...)

Arguments

x

an R object.

...

ignored (possibly used by derived methods).

type, chroma.type

character telling whether "CMF", "CC", or "both" should be returned for human vision, or an object of class chroma_spct for any other trichromic visual system.

short.names

logical indicating whether to use short or long names for wavebands

idx

character Name of the column with the names of the members of the collection of spectra.

Value

A color definition in hexadecimal format as a character string of 7 characters, "#" followed by the red, blue, and green values in hexadecimal (scaled to 0 ... 255). In the case of the specialization for list, a list of such definitions is returned. In the case of a collection of spectra, a data.frame with one column with such definitions and by default an additional column with names of the spectra as index. In case of missing input the returned value is NA.

Methods (by class)

Deprecated

Use of color() is deprecated as this wrapper function may be removed in future versions of the package because of name clashes. Use color_of() instead.

Note

When x is a list but not a waveband, if a method color_of is not available for the class of each element of the list, then color_of.default will be called.

Function fast_color_of_wl() should be used only when high performance is needed. It speeds up performance by rounding the wavelength values in the numeric vector passed as argument to x and then retrieves the corresponding pre-computed color definitions if type is either "CMF" or "CC". In other cases it falls-back to calling color_of.numeric(). Returned color definitions always have default names irrespective of names of x, which is different from the behavior of color_of() methods.

Function fast_color_of_wb() accepts waveband objects and lists of waveband objects. If all wavebands are narrow, it issues a vectotized call to fast_color_of_wl() with a vector of waveband midpoint wavelengths.

Examples

1
2
3
4
5
6
7
8
wavelengths <- c(300, 420, 500, 600, NA) # nanometres
color_of(wavelengths)
color_of(waveband(c(300,400)))
color_of(list(blue = waveband(c(400,480)), red = waveband(c(600,700))))
color_of(numeric())
color_of(NA_real_)

color_of(sun.spct)

photobiology documentation built on Aug. 28, 2020, 1:11 a.m.