Last active
November 12, 2019 13:53
-
-
Save CnrLwlss/402ad5eabfa5c563e20a71186d6ffd3e to your computer and use it in GitHub Desktop.
Checking colour contrasts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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