Skip to content

Instantly share code, notes, and snippets.

@CnrLwlss
Last active November 12, 2019 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CnrLwlss/402ad5eabfa5c563e20a71186d6ffd3e to your computer and use it in GitHub Desktop.
Save CnrLwlss/402ad5eabfa5c563e20a71186d6ffd3e to your computer and use it in GitHub Desktop.
Checking colour contrasts
# Visual comparison of the contrast between colours and different solid backgrounds
colourGrid=function(dimval=20,background="gray",colourfun=rainbow,ptsize=1){
cols=colourfun(dimval^2)
yvals=rep(seq(0,1,length.out=dimval),each=dimval)
xvals=rep(seq(0,1,length.out=dimval),dimval)
plot(xvals,yvals,type="n",xaxt="n",yaxt="n",ann=FALSE, bty="n")
rect(par("usr")[1],par("usr")[3],par("usr")[2],par("usr")[4],col = background,border=NA)
points(xvals,yvals,col=cols,pch=16,cex=ptsize)
}
dimval=20
ptsize=1
op=par(mfrow=c(2,2),mai=c(0.1,0.1,0.1,0.1))
colourGrid(dimval,"gray",rainbow,ptsize)
colourGrid(dimval,"white",rainbow,ptsize)
colourGrid(dimval,"gray",cm.colors,ptsize)
colourGrid(dimval,"white",cm.colors,ptsize)
par(op)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment