hsluv {RcppColors}R Documentation

HSLuv color specification

Description

Converts a color given in HSLuv coordinates to a hexadecimal string or a RGB color specification.

Usage

hsluv(h = 360, s = 100, l = 100, alpha = NULL)

hsluv2rgb(h = 360, s = 100, l = 100)

Arguments

h

the hue, a number between 0 and 360

s

the saturation, a number between 0 and 100

l

the lightness, a number between 0 and 100

alpha

opacity, a number between 0 and 1, or NULL

Value

The hsluv function returns a hexadecimal string representing a color, and the hsluv2rgb returns the RGB coordinates of this color, a named vector of three integers between 0 and 255.

Examples

saturation <- 100
f <- Vectorize(
  function(x, y){
    z <- complex(real = x, imaginary = y)
    modulus <- Mod(z)
    if(modulus > 1){
      return("#ffffff")
    }
    radians <- Arg(z)
    if(radians < 0){
      radians <- radians + 2*pi
    }
    degrees <- 360 * radians / 2 / pi
    hsluv(h = degrees, s = saturation, l = 100*modulus)
  }
)

x <- y <- seq(-1, 1, length.out = 200L)
image <- outer(x, y, f)

opar <- par(mar = c(0, 0, 0, 0))
plot(NULL, xlim = c(-1, 1), ylim = c(-1, 1), asp = 1)
rasterImage(image, -1, -1, 1, 1)
par(opar)

[Package RcppColors version 0.6.0 Index]