~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to dotneato/awk/colortbl.awk

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) AT&T Corp. 1994, 1995.
 
2
# This code is licensed by AT&T Corp.  For the
 
3
# terms and conditions of the license, see
 
4
# http://www.research.att.com/orgs/ssr/book/reuse
 
5
 
 
6
function rgb_to_hsb(r,g,b) {
 
7
        r = r / 255.0; g = g / 255.0; b = b / 255.0;
 
8
        max = r; if (max < g) max = g; if (max < b) max = b;
 
9
        min = r; if (min > g) min = g; if (min > b) min = b;
 
10
        v = max;
 
11
        if (max != 0) s = (max - min) / max;
 
12
        else s = 0;
 
13
        if (s == 0) h = 0;
 
14
        else {
 
15
                delta = max - min;
 
16
                rc = (max - r)/delta;
 
17
                gc = (max - g)/delta;
 
18
                bc = (max - b)/delta;
 
19
                if (r == max) h = bc - gc;
 
20
                else {
 
21
                        if (g == max) h = 2.0 + (rc - bc);
 
22
                        else h = 4.0 + (gc - rc);
 
23
                }
 
24
                h = h * 60.0;
 
25
                if (h < 0.0) h = h + 360.0;
 
26
        }
 
27
        h = h / 360.0 * 255.0;
 
28
        s = s * 255.0;
 
29
        v = v * 255.0;
 
30
}
 
31
 
 
32
BEGIN   { s = ARGV[1]; gsub("\\.","_",s); printf("hsbcolor_t %s[] = {\n",s); }
 
33
/^$/    { next; }
 
34
/^#/    { next; }
 
35
                {
 
36
                        rgb_to_hsb($2,$3,$4);
 
37
                        printf("{\"%s\",%d,%d,%d},\n",$1,h,s,v);
 
38
                }
 
39
END             { printf("};\n"); }