https://github.com/cran/fields
Tip revision: e41cdb90fbcc54695ce1724284e5b3f3abcf643a authored by Doug Nychka on 21 October 2008, 16:58:57 UTC
version 5.01
version 5.01
Tip revision: e41cdb9
fields.color.picker.R
# fields, Tools for spatial data
# Copyright 2004-2007, Institute for Mathematics Applied Geosciences
# University Corporation for Atmospheric Research
# Licensed under the GPL -- www.gpl.org/licenses/gpl.html
fields.color.picker<-function(){
c( mar=c(0,0,3,0) )
# names of colors in default graphics options.
clab<- colors()
n<- length( clab)
N<- ceiling( sqrt(n) )
M<- N
temp<- rep( NA,M*N)
temp[1:n] <- 1:n
z<- matrix(temp, M,N)
# matrix of all colors
image(seq(.5,M+.5,,M+1), seq(.5,N+.5,,N+1)
, z, col=clab, axes=FALSE, xlab="", ylab="")
cat("Use mouse to identify color",fill=TRUE)
locator( 1)-> loc; i<- round( loc$x);j<- round( loc$y);
ind<- z[i,j]
points( i,j, col= clab[ind], cex=4, pch="O")
points( i,j, pch="+", col= "black", cex=1)
mtext( side=3, text=clab[ind], col=clab[ind], line=1, cex=2)
# write out RGB values to console
cat("ID ", ind, " name ", clab[ind],fill=TRUE)
cat( "RGB", col2rgb(clab[ind])/256, fill=TRUE)
temp<- signif(col2rgb(clab[ind])/256, 3)
# This line is marginally in LaTeX format to define color
cat( clab[ind],
" {rgb}{", temp[1],
",", temp[2],
",", temp[3],
"}", fill=TRUE )
}