/[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.14 by jvk, Fri Oct 11 12:17:47 2002 UTC revision 1.15 by jvk, Mon Oct 14 17:49:30 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 gfx.libcolor.spaces import getRandomColor,getRandomColor2,RGBtoLAB,LABtoRGB,LABclamp,getangle  from gfx.libcolor.spaces import getRandomColor,getRandomColor2,YSTtoRGB,clampSat
4    from gfx.libcolor.spaces import RGBtoLAB,LABtoRGB,LABclamp
5    
6  from math import sin,cos,atan2,pi,log  from math import sin,cos,atan2,pi,log
7  from random import Random,shuffle  from random import Random,shuffle
# Line 18  class Colors: Line 19  class Colors:
19    
20          colors = 8          colors = 8
21          minlum = 80          minlum = 80
         #huerange = (45 + rnd.nextGaussian() * 45)  
22          huerange = rnd.nextGaussian() * 90          huerange = rnd.nextGaussian() * 90
23    
24          # Note: This color sampling scheme only produces          # Note: This color sampling scheme only produces
25          # palettes with similar colors.          # palettes with similar colors.
26          # It could be nice to have other schemes          # It could be nice to have other schemes
27          # with, e.g., complementary colors.          # with, e.g., complementary colors.
28          # (Note: color complementing should be done in RGB space)  
29            # Add orange color to the color circle
30            def getangle(f):
31                # 0 = red, 120 = green, 240 = blue
32                angles = [ 0, 30, 60, 120, 180, 240, 300, 360 ]
33                n = len(angles) - 1
34                f *= n / 360.0
35                index = int(f) % n
36                fract = f - int(f)
37                return (1 - fract) * angles[index] + fract * angles[index + 1]
38    
39          # Sample hues uniformly from the range shifted to a random angle          # Sample hues uniformly from the range shifted to a random angle
40          if 0:          hue0 = rnd.nextDouble() * 360
41              huerange *= pi / 180          hues = ([hue0, hue0 + huerange] +
42              hue0 = rnd.nextDouble() * 2*pi                  [hue0 + rnd.nextDouble() * huerange for i in range(2,colors)])
43              hues = ([hue0, hue0 + huerange] +          hues = map(getangle, hues)
44                      [hue0 + rnd.nextDouble() * huerange for i in range(2,colors)])          shuffle(hues, rnd.nextDouble)
             shuffle(hues, rnd.nextDouble)  
         else:  
             huerange /= 360  
             hue0 = rnd.nextDouble()  
             hues = ([hue0, hue0 + huerange] +  
                     [hue0 + rnd.nextDouble() * huerange for i in range(2,colors)])  
             hues = map(getangle, hues)  
             shuffle(hues, rnd.nextDouble)  
           
45    
46          # Take one half dark colors and one half light colors          # Take one half dark colors and one half light colors
47          lumrange = 100 - minlum          lumrange = 100 - minlum
# Line 54  class Colors: Line 54  class Colors:
54          # Sample saturation:          # Sample saturation:
55          #  - take the most saturated color 2/3 of the time          #  - take the most saturated color 2/3 of the time
56          #    and a dull color 1/3 of the time          #    and a dull color 1/3 of the time
57          sats = [100 * (1 - (1 - (1 - rnd.nextDouble())**2) * (rnd.nextDouble() < .333))          sats = [(1 - (1 - (1 - rnd.nextDouble())**2) * (rnd.nextDouble() < .333))
58                  for i in range(0, colors)]                  for i in range(0, colors)]
59    
60          # Construct colors and clamp towards the CIELAB L-axis          # Construct colors and clamp to RGB cube keeping hue and luminance constant
61          # (keeping hue and luminance) to fit into the RGB cube          yst = [(pow((lums[i] + 16.0) / 116, 3),
62          lab = [(lums[i], sats[i] * cos(hues[i]), sats[i] * sin(hues[i]))                  sats[i] * cos(hues[i]*pi/180),
63                 for i in range(0,colors)]                          sats[i] * sin(hues[i]*pi/180))
64          col = [LABclamp(LABtoRGB(c)) for c in lab]                 for i in range(0,colors)]
65                      
66            col = [clampSat(YSTtoRGB(c)) for c in yst]
67          shuffle(col, rnd.nextDouble)          shuffle(col, rnd.nextDouble)
68                    
69          if dbg:          if dbg:

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

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