]> granicus.if.org Git - graphviz/blob - doc/infosrc/mkcolors.awk
5d13bcc4e3f8fa4867577605d658c40d3412a982
[graphviz] / doc / infosrc / mkcolors.awk
1 function max(m,n) {
2   return m > n ? m : n;
3 }
4 function value (r, g, b) {
5   return max(r,max(g,b));
6 }
7 function putColor (n, r, g, b, v)
8 {
9   printf ("<td bgcolor=\"#%02x%02x%02x\" title=\"#%02x%02x%02x\">",r,g,b,r,g,b); 
10   if (v < 0.51) printf ("<font color=\"white\">%s</font>", n);
11   else printf ("%s", n);
12   printf ("</td>\n");
13 }
14 BEGIN {
15   colorsPerRow = 5;
16   if (ARGV[1] == "--single-line") {
17     ARGV[1] = "";
18     name = ARGV[2];
19     singleRow = 1;
20   }
21   else {
22     name = "";
23     singleRow = 0;
24   }
25   if (length(name) > 0) {
26     sub(".*/","",name);
27     printf ("%s color scheme<BR>\n", name);
28   }
29   printf ("<table border=\"1\" align=\"center\" class=\"gv-colors\">\n");
30 }
31 {
32   if (singleRow) idx = NR;
33   else idx = NR % colorsPerRow;
34   if (idx == 1) printf ("<tr align=\"center\">\n");
35   putColor($1,$2,$3,$4,value($2/255.0,$3/255.0,$4/255.0));
36   if (idx == 0) printf ("</tr>\n");
37 }
38 END {
39   if (idx != 0) printf ("</tr>\n");
40   printf ("</table><HR>\n");
41 }