124 |
|
|
125 |
hash = {} |
hash = {} |
126 |
for rgb in colors: |
for rgb in colors: |
127 |
hash[rgb[3]] = (int(rgb[0])/255., |
hash[" ".join(rgb[3:])] = (int(rgb[0])/255., |
128 |
int(rgb[1])/255., |
int(rgb[1])/255., |
129 |
int(rgb[2])/255.) |
int(rgb[2])/255.) |
130 |
return hash |
return hash |
131 |
|
|
132 |
class CIELABScene: |
class CIELABScene: |
274 |
class CIELABScene2: |
class CIELABScene2: |
275 |
def __init__(self): |
def __init__(self): |
276 |
self.angle = None |
self.angle = None |
277 |
|
self.angle2 = 0 |
278 |
self.colors = None |
self.colors = None |
279 |
|
self.map = None |
280 |
|
self.dsiz = 4 |
281 |
|
|
282 |
def key(self, k): |
def key(self, k): |
283 |
a = self.angle or 0 |
a = self.angle or 0 |
284 |
if k == "+": self.angle = a + 5 |
if k == "Left": self.angle = a + 5 |
285 |
if k == "-": self.angle = a - 5 |
if k == "Right": self.angle = a - 5 |
286 |
|
if k == "Up": self.angle2 += 5 |
287 |
|
if k == "Down": self.angle2 -= 5 |
288 |
if k == "0": self.angle = None |
if k == "0": self.angle = None |
289 |
if k == "c": |
if k == "c": self.colors = readcolors().values() |
290 |
self.colors = readcolors().values() |
AbstractUpdateManager.setNoAnimation() |
291 |
|
|
292 |
|
def mouse(self, ev): |
293 |
|
global globalx, globaly |
294 |
|
if ev.getID() == ev.MOUSE_CLICKED: |
295 |
|
dsiz = 800 |
296 |
|
(a,b) = ((ev.getX() - 600.0) / self.dsiz, |
297 |
|
(ev.getY() - 450.0) / self.dsiz) |
298 |
|
print "A,B=", a,b |
299 |
|
minr2 = 1E8 |
300 |
|
if not self.map: self.map = readcolors() |
301 |
|
for name in self.map.keys(): |
302 |
|
lab = RGBtoLAB(self.map[name]) |
303 |
|
r2 = round((lab[1]-a)**2 + (lab[2]-b)**2, 2) |
304 |
|
if r2 < minr2: |
305 |
|
minr2 = r2 |
306 |
|
best = [name] |
307 |
|
elif r2 == minr2: |
308 |
|
best += [name] |
309 |
|
print "Best matches:" |
310 |
|
def round1(x): return round(x,1) |
311 |
|
def round2(x): return round(100*x,1) |
312 |
|
for name in best: |
313 |
|
rgb = self.map[name] |
314 |
|
print "%s: LAB=%s RGB=%s" % (name, |
315 |
|
map(round1, RGBtoLAB(rgb)), |
316 |
|
map(round2, rgb)) |
317 |
|
|
318 |
|
AbstractUpdateManager.setNoAnimation() |
319 |
|
|
320 |
|
|
321 |
def scene(self, vs): |
def scene(self, vs): |
322 |
putnoc(vs, background((1.0,1.0,1.0))) |
putnoc(vs, background((1.0,1.0,1.0))) |
331 |
Color 1 0.1 1 |
Color 1 0.1 1 |
332 |
""")) |
""")) |
333 |
|
|
|
dsiz = 800 |
|
334 |
n = 16 |
n = 16 |
335 |
|
cs = vs.coords.affineCoordsys(0, 10, 600, 450, |
336 |
|
self.dsiz, 0, 0, self.dsiz) |
337 |
|
vs.matcher.add(cs, "foo") |
338 |
|
|
339 |
if not self.colors: |
if not self.colors: |
340 |
for b in range(0,n): |
for b in range(0,n): |
341 |
l = 100 * (b+.5) /n |
l = 100 * (b+.5) /n |
342 |
|
vs.map.put(GLRen.createLABSlice(0, l), cs) |
343 |
|
|
|
vs.put(GLRen.createLABSlice(0, l), |
|
|
"labslice"+str(b), |
|
|
10, 600, 450, dsiz*.01, dsiz*.01) |
|
|
|
|
|
cs = vs.coords.affineCoordsys(0, 10, 600, 450, |
|
|
dsiz*.005, 0, 0, dsiz*.005) |
|
|
vs.matcher.add(cs, "foo") |
|
344 |
|
|
345 |
vs.map.put(getDList(""" |
vs.map.put(getDList(""" |
346 |
Color 1 1 1 |
Color 1 1 1 |
385 |
Vertex 200 +150 |
Vertex 200 +150 |
386 |
Vertex 200 -150 |
Vertex 200 -150 |
387 |
End |
End |
388 |
|
Rotate %s 0 0 1 |
389 |
|
Color 1 1 1 |
390 |
|
Begin QUADS |
391 |
|
Vertex 0 -150 |
392 |
|
Vertex 0 +150 |
393 |
|
Vertex 200 +150 |
394 |
|
Vertex 200 -150 |
395 |
|
End |
396 |
PopMatrix |
PopMatrix |
397 |
""" % (self.angle)), cs) |
""" % (self.angle, self.angle2)), cs) |
398 |
|
|
399 |
|
|
400 |
putnoc(vs, getDList(""" |
putnoc(vs, getDList(""" |