[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] gzz/gfx libcolor/spaces.py libpaper/colors.py
From: |
Janne V. Kujala |
Subject: |
[Gzz-commits] gzz/gfx libcolor/spaces.py libpaper/colors.py |
Date: |
Fri, 27 Sep 2002 10:05:08 -0400 |
CVSROOT: /cvsroot/gzz
Module name: gzz
Changes by: Janne V. Kujala <address@hidden> 02/09/27 10:05:08
Modified files:
gfx/libcolor : spaces.py
gfx/libpaper : colors.py
Log message:
Rewrite color sampling; the previous code produced only saturated colors
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libcolor/spaces.py.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libpaper/colors.py.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
Patches:
Index: gzz/gfx/libcolor/spaces.py
diff -c gzz/gfx/libcolor/spaces.py:1.7 gzz/gfx/libcolor/spaces.py:1.8
*** gzz/gfx/libcolor/spaces.py:1.7 Fri Sep 27 07:55:28 2002
--- gzz/gfx/libcolor/spaces.py Fri Sep 27 10:05:08 2002
***************
*** 59,64 ****
--- 59,65 ----
L = minL + (maxL - minL) * rnd.nextDouble()
a = 200 * rnd.nextDouble() - 100
b = 200 * rnd.nextDouble() - 100
+ # XXX: (a,b) is sampled from a square
rgb = LABtoRGB([L,a,b])
return rgb
***************
*** 74,101 ****
rgb = [-1]
L = minL + (maxL - minL) * rnd.nextDouble()
ang = rnd.nextDouble() * 2 * math.pi
! a = 100 * math.cos(ang)
! b = 100 * math.sin(ang)
! rgb = LABtoRGB([L,a,b])
!
! return LABclamp(rgb)
!
!
! def getRandomColor3(minL, maxL, hue_avg, hue_sd, rnd):
! """Get a random color deterministically with Gaussian hue
!
! minL, maxL: minimum and maximum luminance value
! hue_avg, hue_sd: hue distribution parameters in degerees
! rnd: a random number generator, corresponding to
! java.util.Random for the API. The same color
! is always returned if the PRNG returns the
! same list of values.
! """
! rgb = [-1]
! L = minL + (maxL - minL) * rnd.nextDouble()
! ang = (hue_avg + rnd.nextGaussian() * hue_sd) / 180 * math.pi
! a = 100 * math.cos(ang)
! b = 100 * math.sin(ang)
rgb = LABtoRGB([L,a,b])
return LABclamp(rgb)
--- 75,86 ----
rgb = [-1]
L = minL + (maxL - minL) * rnd.nextDouble()
ang = rnd.nextDouble() * 2 * math.pi
! r = rnd.nextDouble() * 100
! # XXX: used to be "r = 100" producing only saturated colors!
! # XXX: sampling saturation from the uniform distribution
! # is not necessarily ideal
! a = r * math.cos(ang)
! b = r * math.sin(ang)
rgb = LABtoRGB([L,a,b])
return LABclamp(rgb)
Index: gzz/gfx/libpaper/colors.py
diff -c gzz/gfx/libpaper/colors.py:1.9 gzz/gfx/libpaper/colors.py:1.10
*** gzz/gfx/libpaper/colors.py:1.9 Wed Sep 25 10:00:19 2002
--- gzz/gfx/libpaper/colors.py Fri Sep 27 10:05:08 2002
***************
*** 1,45 ****
# Choosing colors and 3-dotproduct factors for papers.
! from gfx.libcolor.spaces import getRandomColor,getRandomColor2,RGBtoLAB
! from math import atan2,pi
import java;
class Colors:
def _js(self, arg):
return " ".join([str(a) for a in arg])
def __init__(self, seed):
rnd = self.rnd = java.util.Random(seed)
# currently, 4 colors
minlum = 80
! # Just take alternating dark and light colors
! while 1:
! t = (100 - minlum)/2
! col = [ getRandomColor2(minlum + t - t * (i & 1),
! 100 - t * (i & 1), rnd)
! for i in range(0,4) ]
! if 120 - self._AB_angle(col) > 90 * rnd.nextFloat(): break
! #if self._AB_angle(col) < 180: break
! print "ANGLE=", self._AB_angle(col), "AREA=", self._AB_area(col)*100
!
! while 0:
! col = [
! getRandomColor2(minlum,100, rnd),
! getRandomColor2(minlum,minlum + (100-minlum)*0.7, rnd),
! getRandomColor2(minlum + (100-minlum)*0.7, 100, rnd),
! # getRandomColor2(minlum + (100-minlum)*0.5, 100, rnd),
! ]
! #print self._AB_angle(col)
! #print self._AB_avg_dot(col)
! # if abdiff(col[0], col[1]) < 40: continue
! #if abdiff(col0, col2) < 40: continue
! #if abdiff(col0, col3) < 40: continue
! #if abdiff(col1, col2) < 40: continue
! #if abdiff(col1, col3) < 40: continue
! # if abdiff(col[2], col[3]) < 40: continue
! break
self.colors = [self._js(c) for c in col]
--- 1,58 ----
# Choosing colors and 3-dotproduct factors for papers.
! from gfx.libcolor.spaces import
getRandomColor,getRandomColor2,RGBtoLAB,LABtoRGB,LABclamp
! from math import sin,cos,atan2,pi
! from random import shuffle
import java;
+ dbg=0
+
class Colors:
def _js(self, arg):
return " ".join([str(a) for a in arg])
def __init__(self, seed):
rnd = self.rnd = java.util.Random(seed)
+
# currently, 4 colors
+ colors = 4
minlum = 80
+ huerange = (45 + rnd.nextGaussian() * 45) * (pi / 180)
+
+ # Note: This color sampling scheme only produces
+ # palettes with similar colors.
+ # It could be nice to have other schemes
+ # with, e.g., complementary colors.
+ # (Note: color complementing should be done in RGB space)
+
+ # Sample hues uniformly from the range shifted to a random angle
+ hue0 = rnd.nextDouble() * 2*pi
+ hues = [hue0 + rnd.nextDouble() * huerange for i in range(0,colors)]
+
+ # Take one half dark colors and one half light colors
+ lumrange = 100 - minlum
+ lums = ([minlum + rnd.nextDouble() * lumrange/2
+ for i in range(0,colors/2)] +
+ [minlum + (1 + rnd.nextDouble()) * lumrange/2
+ for i in range(colors/2,colors)]
+ )
+
+ # Sample saturation:
+ # - take the most saturated color 2/3 of the time
+ # and a dull color 1/3 of the time
+ sats = [100 * (1 - (1 - (1 - rnd.nextDouble())**2) *
(rnd.nextDouble() < .333))
+ for i in range(0, colors)]
! # Construct colors and clamp towards the CIELAB L-axis
! # (keeping hue and luminance) to fit into the RGB cube
! lab = [(lums[i], sats[i] * cos(hues[i]), sats[i] * sin(hues[i]))
! for i in range(0,colors)]
! col = [LABclamp(LABtoRGB(c)) for c in lab]
! shuffle(col, rnd.nextDouble)
!
! if dbg:
! print "ANGLE=", self._AB_angle(col), "AREA=",
self._AB_area(col)*100
self.colors = [self._js(c) for c in col]
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gzz-commits] gzz/gfx libcolor/spaces.py libpaper/colors.py,
Janne V. Kujala <=