Six C++ functions are exposed by this package:
std::string rgb2hex(double r, double g, double b);
std::string rgba2hex(double r, double g, double b, double a);
std::string hsluv2hex(double h, double s, double l);
std::string hsluv2hex(double h, double s, double l, double alpha);
std::string hsv2hex(double h, double s, double v);
std::string hsv2hex(double h, double s, double v, double alpha);
r, g, b ∈ [0, 255] (red, green, blue)
a, alpha ∈ [0, 1] (opacity)
h ∈ [0, 360] (hue)
s,l,v ∈ [0, 100] (saturation, lightness, value)
The LinkingTo field in the DESCRIPTION file should look like
LinkingTo:
Rcpp,
RcppColors
Then, in your C++ file, you can call the above functions like this:
#include <RcppColors.h>
std::string mycolor = RcppColors::rgb2hex(0.0, 128.0, 255.0);
library(RcppColors)
library(Bessel)
<- y <- seq(-4, 4, len = 1500)
x # complex grid
<- outer(y, x, function(x, y) complex(real = x, imaginary = y))
W # computes Bessel values
<- matrix(BesselY(W, nu = 3), nrow = nrow(W), ncol = ncol(W))
Z # maps them to colors
<- colorMap1(Z)
image # plot
<- par(mar = c(0,0,0,0), bg = "#15191E")
opar plot(
c(-100, 100), c(-100, 100), type = "n",
xlab = "", ylab = "", axes = FALSE, asp = 1
)rasterImage(image, -100, -100, 100, 100)
par(opar)
library(RcppColors)
library(Carlson)
library(rgl)
library(Rvcg)
<- vcgSphere(subdivision = 8)
mesh
<- apply(mesh$vb[-4L, ], 2L, function(xyz){
color if(sum(xyz == 0) >= 2){
<- NA_complex_
z else{
}<- xyz[1]
a <- xyz[2]
b <- xyz[3]
c <- Carlson_RJ(a, b, c, 1i, 1e-5)
z
}colorMap1(z)
})
$material <- list(color = color)
mesh
open3d(windowRect = c(50, 50, 562, 562), zoom = 0.75)
bg3d("whitesmoke")
shade3d(mesh)
library(RcppColors)
library(jacobi)
library(rgl)
library(Rvcg)
<- vcgSphere(subdivision = 8)
mesh
<- apply(mesh$vb[-4L, ], 2L, function(xyz){
color <- xyz[1]
a <- xyz[2]
b <- xyz[3]
c <- wzeta(a + 1i* b, tau = (1i+c)/2)
z colorMap1(z)
})
$material <- list(color = color)
mesh
open3d(windowRect = c(50, 50, 562, 562), zoom = 0.75)
bg3d("palevioletred2")
shade3d(mesh)
library(RcppColors)
<- Vectorize(function(x, y, tau0 = 0, gamma = 2.5){
ikeda for(k in 1L:5L){
<- tau0 - 6.0/(1.0 + x*x + y*y)
tau <- 0.97 + gamma * (x*cos(tau) - y*sin(tau))
newx <- gamma * (x*sin(tau)+y*cos(tau))
y <- newx
x
}<- complex(real = x, imaginary = y)
z colorMap1(z, reverse = c(TRUE, FALSE, FALSE))
})
<- y <- seq(-3, 3, len = 3000)
x <- outer(y, x, function(x, y) ikeda(x, y))
image
<- par(mar = c(0,0,0,0), bg = "#002240")
opar plot(
c(-100, 100), c(-100, 100), type = "n",
xlab = "", ylab = "", axes = FALSE, asp = 1
)rasterImage(image, -100, -100, 100, 100)
par(opar)
library(RcppColors)
library(jacobi)
<- Vectorize(function(q){
f if(Mod(q) > 1 || (Im(q) == 0 && Re(q) <= 0)){
<- NA_complex_
z else{
}<- EisensteinE(6, q)
z
}colorMap2(z, bkgcolor = "#002240")
})
<- y <- seq(-1, 1, len = 2000)
x <- outer(y, x, function(x, y){
image f(complex(real = x, imaginary = y))
})
<- par(mar = c(0,0,0,0), bg = "#002240")
opar plot(
c(-100, 100), c(-100, 100), type = "n",
xlab = "", ylab = "", axes = FALSE, asp = 1
)rasterImage(image, -100, -100, 100, 100)
par(opar)
library(RcppColors)
library(jacobi)
<- Vectorize(function(q){
f if(Mod(q) >= 1){
NA_complex_
else{
}<- -1i * log(q) / pi
tau if(Im(tau) <= 0){
NA_complex_
else{
}kleinj(tau) / 1728
}
}
})
<- y <- seq(-1, 1, len = 3000)
x <- outer(y, x, function(x, y){
Z f(complex(real = x, imaginary = y))
})<- colorMap2(1/Z, bkgcolor = "#002240", reverse = c(T,T,T))
image
<- par(mar = c(0,0,0,0), bg = "#002240")
opar plot(
c(-100, 100), c(-100, 100), type = "n",
xlab = "", ylab = "", axes = FALSE, asp = 1
)rasterImage(image, -100, -100, 100, 100)
par(opar)
library(RcppColors)
library(jacobi)
library(rgl)
library(Rvcg)
library(pracma)
<- vcgSphere(8)
mesh <- cart2sph(t(mesh$vb[-4L, ]))
sphcoords <- sphcoords[, 1L] / pi
theta <- sphcoords[, 2L] / pi * 2
phi <- wsigma(theta + 1i * phi, tau = 2+2i)
Z <- colorMap1(Z, reverse = c(TRUE, FALSE, TRUE))
color $material <- list(color = color)
mesh
open3d(windowRect = c(50, 50, 562, 562), zoom = 0.75)
bg3d("lightgrey")
shade3d(mesh)