/[gzz]/gzz/gfx/demo/color/colors.py
ViewVC logotype

Diff of /gzz/gfx/demo/color/colors.py

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

revision 1.5 by jvk, Wed Sep 25 11:28:11 2002 UTC revision 1.6 by jvk, Sun Sep 29 08:33:37 2002 UTC
# Line 116  class ColorScene: Line 116  class ColorScene:
116          """))          """))
117    
118    
119    def readcolors():
120        file = open("/etc/X11/rgb.txt", "r")
121        lines = file.readlines()
122        file.close()
123        colors = [ line.split() for line in lines[1:] ]
124    
125        hash = {}
126        for rgb in colors:
127            hash[rgb[3]] = (int(rgb[0])/255.,
128                            int(rgb[1])/255.,
129                            int(rgb[2])/255.)
130        return hash
131    
132  class CIELABScene:  class CIELABScene:
133      def __init__(self):      def __init__(self):
134          self.labhexes = {}          self.labhexes = {}
# Line 123  class CIELABScene: Line 136  class CIELABScene:
136      def key(self, k):      def key(self, k):
137          if k == "v":          if k == "v":
138              self.recolor()              self.recolor()
139            if k == "c":
140                self.colors = readcolors().values()
141                
142      def labhex(self, b):      def labhex(self, b):
143          # Bases:          # Bases:
144          # (1,1,1)          # (1,1,1)
# Line 239  class CIELABScene: Line 255  class CIELABScene:
255              b = int(round(lab[0] * 16 / 100 - .5))              b = int(round(lab[0] * 16 / 100 - .5))
256              #print js(col)+"--->"+str(b)+" "+js(lab)              #print js(col)+"--->"+str(b)+" "+js(lab)
257              vs.put(getDList("""              vs.put(getDList("""
258                          PointSize 6                          PointSize 3
259                          Begin POINTS                          Begin POINTS
260                          Color 0 0 0                          Color 0 0 0
261                          Vertex %s                          Vertex %s
# Line 258  class CIELABScene: Line 274  class CIELABScene:
274  class CIELABScene2:  class CIELABScene2:
275      def __init__(self):      def __init__(self):
276          self.angle = None          self.angle = None
277            self.colors = None
278      def key(self, k):      def key(self, k):
279          a = self.angle or 0          a = self.angle or 0
280          if k == "+": self.angle = a + 5          if k == "+": self.angle = a + 5
281          if k == "-": self.angle = a - 5          if k == "-": self.angle = a - 5
282          if k == "0": self.angle = None          if k == "0": self.angle = None
283                    if k == "c":
284          pass              self.colors = readcolors().values()
285    
286      def scene(self, vs):      def scene(self, vs):
287          putnoc(vs, background((1.0,1.0,1.0)))          putnoc(vs, background((1.0,1.0,1.0)))
288    
# Line 280  class CIELABScene2: Line 298  class CIELABScene2:
298    
299          dsiz = 800          dsiz = 800
300          n = 16          n = 16
301          for b in range(0,n):          if not self.colors:
302              l = 100 * (b+.5) /n              for b in range(0,n):
303                    l = 100 * (b+.5) /n
304              vs.put(GLRen.createLABSlice(0, l),  
305                     "labslice"+str(b),                  vs.put(GLRen.createLABSlice(0, l),
306                     10, 600, 450, dsiz*.01, dsiz*.01)                         "labslice"+str(b),
307                           10, 600, 450, dsiz*.01, dsiz*.01)
308    
309          cs = vs.coords.affineCoordsys(0, "foo", 10, 600, 450,          cs = vs.coords.affineCoordsys(0, 10, 600, 450,
310                                        dsiz*.005, 0, 0, dsiz*.005)                                        dsiz*.005, 0, 0, dsiz*.005)
311            vs.matcher.add(cs, "foo")
312    
313          vs.map.put(getDList("""          vs.map.put(getDList("""
314              Color 1 1 1              Color 1 1 1
# Line 301  class CIELABScene2: Line 321  class CIELABScene2:
321          """), cs)          """), cs)
322    
323          i = 0          i = 0
324          for rgb in [ (1,0,0), (1,.5,0), (1,1,0), (.5,1,0),          for rgb in self.colors or [
325                         (1,0,0), (1,.5,0), (1,1,0), (.5,1,0),
326                       (0,1,0), (0,1,.5), (0,1,1), (0,.5,1),                       (0,1,0), (0,1,.5), (0,1,1), (0,.5,1),
327                       (0,0,1), (.5,0,1), (1,0,1), (1,0,.5) ]:                       (0,0,1), (.5,0,1), (1,0,1), (1,0,.5) ]:
328              lab = RGBtoLAB(rgb)              lab = RGBtoLAB(rgb)
329                if self.colors:
330                    size = 8
331                else:
332                    size = 10 - 5*i
333                    rgb = (0,0,0)
334                
335              vs.map.put(getDList("""              vs.map.put(getDList("""
336              Color 0 0 0              Color %s %s %s
337              PointSize %s              PointSize %s
338              Begin POINTS              Begin POINTS
339              Vertex %s %s              Vertex %s %s
340              End              End
341              """ % (10 - 5*i, lab[1], lab[2])), cs)              """ % (rgb[0], rgb[1], rgb[2],
342                       size, lab[1], lab[2])), cs)
343              i = 1 - i              i = 1 - i
344    
345          if self.angle != None:          if self.angle != None:

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

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