# pickColor.R # # Plot colors()-vector, click on the color(s) to get the name(s). That's it. # # Author: Tuomas Rajala # ############################################################################### pickColor<-function(n=1,numbers=F) { ncol<-30 nrow<-22 x<-0:ncol y<-0:nrow col<-c(colors(), rep("white", ncol*nrow-length(colors()) ) ) a<-array(1:length(col),dim=c(ncol,nrow)) p<-"Pick a color:" if(n>1)p<-paste("Pick",n,"colors:") image(x,y,a,col=array(col,dim=c(ncol,nrow)),xaxt="n",yaxt="n",main=p,xlab="",ylab="") loc<-locator(n=n) a<-array(col,dim=c(ncol,nrow)) res<-NULL if(!is.null(loc)) for(i in 1:length(loc$x)) res<-c(res, a[ceiling(loc$x[i]),ceiling(loc$y[i])] ) if(numbers) res<-which(colors()==res) res }