# output all colors() in R, into an HTML file. # 2021/11/3 ##################### # using R length(colors()) #657=25col*26.28row head(colors()) #"white" "aliceblue" "antiquewhite" df2=NULL; for(i in 1:length(colors())){ color_name=colors()[i] #get each color col2=col2rgb(color_name); #color name to rgb col3=rgb( t(col2), maxColorValue = 255 ) #rgb to hexa "#9ACD32" df2=rbind(df2, data.frame( name=color_name, rgb=paste0("rgb(", col2[1,1],",", col2[2,1],",", col2[3,1],")"), hexa=col3 )) } dim(df2) #657 3 head(df2) # name rgb hexa #1 white rgb(255,255,255) #FFFFFF #2 aliceblue rgb(240,248,255) #F0F8FF write.table(df2, "colorsInR.txt", quote = F) ##################### ## using Python3 (v1) fr=open("colorsInR.txt") fw=open("colorsInR.html", "w") import re fw.write("""

colors() in R

""") fw.write("
\n"); i=0 for lineR in fr.readlines(): line=lineR.strip(); i+=1 if i==1: continue; arr=re.split("\s", line) newLine="
"+arr[1]+"
" fw.write(newLine+'\n') print("end") fw.write("
") fr.close() fw.close() ##################### ## using Python3 (v2) import os os.chdir("/data/wangjl/apa/APA_GO_plot") os.getcwd() def isDark(rgb): import re rs=re.split("[^0-9]+", rgb) return int(rs[1])*0.3 + int(rs[2])*0.59 + int(rs[3])*0.11 < 150 #isDark(arr[2]) isDark('rgb(154,205,50)') fr=open("colorsInR.txt") fw=open("colorsInR.html", "w") import re fw.write(""" """) fw.write("
\n"); fw.write("

657 colors() in R: ordered by columns

\n") i=0 j=0 #real line number, no head line # store Div by columns db={} #657/10 col=65.7 row: 9*66 + 63 #657/12 col=54.75 row: 11*55 + 52 import math total=657 nCol=12 # setting column number nRow=math.ceil(total/nCol); #55 nLastRow = total - nRow * (nCol-1) nLastRow #52 key=0 for lineR in fr.readlines(): line=lineR.strip(); i+=1 if i==1: continue; j+=1 if key not in db: db[key]=[] arr=re.split("\s", line) fontColor="" #default font color: black # when bg is dark, use font color: white if isDark(arr[2]): fontColor=" white" newLine="
"+arr[1]+"
" db[key].append(newLine) if j%nRow==0: key+=1 # write Div to html file for i in range(0,nRow): for c in range(0,nCol): if len(db[c])>i: fw.write(db[c][i] + "\n") fw.write("
\n") fw.write("
") fr.close() fw.close() print("end")