Title: | Generation of Random Colors |
---|---|
Description: | Generation of random colors, possibly with a given hue or a given luminosity. This is a port of the JavaScript library 'randomColor' <https://randomcolor.lllllllllllllllll.com/>. |
Authors: | Stéphane Laurent [aut, cre], David Merfield [cph] ('randomColor' JavaScript library) |
Maintainer: | Stéphane Laurent <[email protected]> |
License: | CC0 |
Version: | 1.0.0 |
Built: | 2024-10-25 04:01:06 UTC |
Source: | https://github.com/stla/colorsgen |
Generate random colors.
randomColor(n, hue = "random", luminosity = "random")
randomColor(n, hue = "random", luminosity = "random")
n |
number of colors to be generated |
hue |
the desired hue; it can be a number between 0 and 360, a hexadecimal color code, or a string taken among the possibilities "random", "red", "orange", "yellow", "green", "blue", "purple", "pink", or "monochrome" |
luminosity |
the desired luminosity, a string taken among the possible choices "random", "light", "bright", or "dark" |
A character vector of hexadecimal color codes.
# pie chart #### n <- 20 clrs <- randomColor(n, hue = "red", luminosity = "dark") opar <- par(mar = c(0, 0, 0, 0)) pie(rep(1, n), col = clrs) par(opar) # Fermat spiral #### n <- 400 theta <- seq(0, n/3, length.out = n) x <- sqrt(theta) * cos(theta) y <- sqrt(theta) * sin(theta) pts <- cbind(x, y) clrs <- randomColor(n, hue = "random", luminosity = "bright") opar <- par(mar = c(0, 0, 0, 0), bg = "black") plot( pts, asp = 1, xlab = NA, ylab = NA, axes = FALSE, pch = 19, col = clrs ) par(opar)
# pie chart #### n <- 20 clrs <- randomColor(n, hue = "red", luminosity = "dark") opar <- par(mar = c(0, 0, 0, 0)) pie(rep(1, n), col = clrs) par(opar) # Fermat spiral #### n <- 400 theta <- seq(0, n/3, length.out = n) x <- sqrt(theta) * cos(theta) y <- sqrt(theta) * sin(theta) pts <- cbind(x, y) clrs <- randomColor(n, hue = "random", luminosity = "bright") opar <- par(mar = c(0, 0, 0, 0), bg = "black") plot( pts, asp = 1, xlab = NA, ylab = NA, axes = FALSE, pch = 19, col = clrs ) par(opar)