/[gzz]/gzz/gfx/libpaper/colors.py
ViewVC logotype

Diff of /gzz/gfx/libpaper/colors.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by tjl, Thu Sep 19 03:08:24 2002 UTC revision 1.5 by jvk, Sat Sep 21 11:13:54 2002 UTC
# Line 1  Line 1 
1  # Choosing colors and 3-dotproduct factors for papers.  # Choosing colors and 3-dotproduct factors for papers.
2    
3    from math import atan2,pi
4    
5  class Colors:  class Colors:
6      def _js(self, arg):      def _js(self, arg):
7          return " ".join([str(a) for a in arg])          return " ".join([str(a) for a in arg])
# Line 14  class Colors: Line 16  class Colors:
16                  getRandomColor2(minlum + (100-minlum)*0.7, 100, rnd),                  getRandomColor2(minlum + (100-minlum)*0.7, 100, rnd),
17                  # getRandomColor2(minlum + (100-minlum)*0.5, 100, rnd),                  # getRandomColor2(minlum + (100-minlum)*0.5, 100, rnd),
18              ]              ]
19                #print self._AB_angle(col)
20                #print self._AB_avg_dot(col)
21              # if abdiff(col[0], col[1]) < 40: continue              # if abdiff(col[0], col[1]) < 40: continue
22              #if abdiff(col0, col2) < 40: continue              #if abdiff(col0, col2) < 40: continue
23              #if abdiff(col0, col3) < 40: continue              #if abdiff(col0, col3) < 40: continue
# Line 40  class Colors: Line 44  class Colors:
44    
45      def getNVDP3VecStr(self, ind):      def getNVDP3VecStr(self, ind):
46          return self._js(self.randvecs[ind % len(self.randvecs)])+" 1"          return self._js(self.randvecs[ind % len(self.randvecs)])+" 1"
47    
48        def _AB_angle(self, cols):
49            print cols
50            getangle = lambda lab: 180 / pi * atan2(lab[2], lab[1])
51            angles = [ getangle(RGBtoLAB(col)) for col in cols ]
52            print angles
53            angles.sort()
54            print angles
55            n = len(angles)
56            maxd = 0
57            for i in range(0, n):
58                if i == n - 1:
59                    d = angles[0] + 360 - angles[i]
60                else:
61                    d = angles[i + 1] - angles[i]
62                maxd = max(d, maxd)
63            return 360 - maxd
64    
65        def _AB_avg_dot(self, cols):
66            print cols
67            ab = [ (lab[1]/100.0,lab[2]/100.0) for lab in map(RGBtoLAB, cols) ]
68    
69            dot = lambda x,y: x[0] * y[0] + x[1] * y[1]
70            dots = [ dot(x,y) for x in ab for y in ab ]
71    
72            return reduce(lambda x,y: x+y, dots) / len(dots)
73        

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26