Skip to content

Instantly share code, notes, and snippets.

@markheckmann
Last active March 1, 2018 21:16
Show Gist options
  • Save markheckmann/ad12685ee63cb47e9ebd to your computer and use it in GitHub Desktop.
Save markheckmann/ad12685ee63cb47e9ebd to your computer and use it in GitHub Desktop.
Color wheels using colorspace::hcl by luminance
library(colorspace)
polar2cart <- function(r, theta) # polar to cartesian coords
{
rad <- theta * pi /180
cbind(x = r*cos(rad),
y = r*sin(rad))
}
h <- seq(0, 360, len=150) # hue values
c <- seq(0, 100, len=100) # chroma
p <- expand.grid(h=h,c=c)
xy <- polar2cart(p$c, p$h)
color_wheel <- function(l=50)
{
col <- hcl(p$h, p$c, l)
plot(xy, pch=16, col=col, asp=1, axes=F,
main=paste("luminance:", round(l)),
xlab="", ylab="")
}
par(mfrow=c(2,2))
for (l in seq(0, 100, len=4))
color_wheel(l)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment