color_space
index
/home/downey/public_html/color/color_space.py

This module uses color_list and Visual Python to 
draw the X11 colors as spheres in 3-D RGB space.
 
The size of the spheres (can be) proportional to the distance
to the nearest neighbor.
 
Users can zoom and rotate using the usual Visual interface:
 
* Drag middle button up and down to zoom in and out.
 
* Drag right button to rotate.
 
Clicking on a sphere prints the color names and toggles a label.
 
Allen B. Downey
2008

 
Modules
       
visual.array_backend
atexit
visual.crayola
copy
copy_reg
visual.crayola
cvisual
math
multiarray
pickle
visual.primitives
string
sys
time
types
visual.ui
Numeric

 
Functions
       
acos(...)
acos(x)
 
Return the arc cosine (measured in radians) of x.
arange(...)
arange(start, stop=None, step=1, typecode=None)
 
 Just like range() except it returns an array whose type can be
specified by the keyword argument typecode.
array(...)
array(sequence, typecode=None, copy=1, savespace=0) will return a new array formed from the given (potentially nested) sequence with type given by typecode.  If no typecode is given, then the type will be determined as the minimum type required to hold the objects in sequence.  If copy is zero and sequence is already an array, a reference will be returned.  If savespace is nonzero, the new array will maintain its precision in operations.
arrayrange = arange(...)
arange(start, stop=None, step=1, typecode=None)
 
 Just like range() except it returns an array whose type can be
specified by the keyword argument typecode.
asin(...)
asin(x)
 
Return the arc sine (measured in radians) of x.
atan(...)
atan(x)
 
Return the arc tangent (measured in radians) of x.
atan2(...)
atan2(y, x)
 
Return the arc tangent (measured in radians) of y/x.
Unlike atan(y/x), the signs of both x and y are considered.
choose(...)
choose(a, (b1,b2,...))
comp(...)
The scalar projection of arg1 to arg2.
C++ signature:
    comp(visual::vector, visual::vector) -> double
cross(...)
C++ signature:
    cross(boost::python::numeric::array, boost::python::numeric::array) -> boost::python::numeric::array
C++ signature:
    cross(boost::python::numeric::array, visual::vector) -> boost::python::numeric::array
C++ signature:
    cross(visual::vector, boost::python::numeric::array) -> boost::python::numeric::array
 
The cross product between two vectors.
C++ signature:
    cross(visual::vector, visual::vector) -> visual::vector
cross_correlate(...)
cross_correlate(a,v, mode=0)
degrees(...)
degrees(x) -> converts angle x from radians to degrees
diff_angle(...)
The angle between two vectors, in radians.
C++ signature:
    diff_angle(visual::vector, visual::vector) -> double
draw_spheres(rgbs, radius=10)
rgbs is a dictionary that maps from an rgb tuple to a
list of color names.  rgb values are in the range 0-255.
 
draws one sphere for each rgb tuple with the given radius,
and returns a list of sphere objects.
 
the sphere objects have the color names as an attribute.
empty(...)
empty((d1,...,dn),typecode='l',savespace=0) will return a new array
of shape (d1,...,dn) and given type with all its entries uninitialized.  If savespace is
nonzero, the array will be a spacesaver array.  This can be faster than zeros.
find_biggest_hole(spheres)
of the web safe colors, find the one whose nearest neighbor
is the farthest.  the answer is (51, 51, 255) or #3333ff
which is a nive shade of blue that deserves a name.
find_closest_sphere(m, spheres)
given the mouse information in (m), find the closest
sphere that is intersected by the line from the camera
to the mouse click.
find_nearest_neighbor(s, spheres)
of the objects in (spheres) find the one closest to s
and return a tuple (distance, closest_object)
frexp(...)
frexp(x)
 
Return the mantissa and exponent of x, as pair (m, e).
m is a float and e is an int, such that x = m * 2.**e.
If x is 0, m and e are both 0.  Else 0.5 <= abs(m) < 1.0.
fromstring(...)
fromstring(string, typecode='l', count=-1) returns a new 1d array initialized from the raw binary data in string.  If count is positive, the new array will have count elements, otherwise it's size is determined by the size of string.
ldexp(...)
ldexp(x, i) -> x * (2**i)
mag(...)
C++ signature:
    mag(boost::python::numeric::array) -> boost::python::api::object
 
The magnitude of a vector.
C++ signature:
    mag(visual::vector) -> double
mag2(...)
C++ signature:
    mag2(boost::python::numeric::array) -> boost::python::api::object
 
A vector's magnitude squared.
C++ signature:
    mag2(visual::vector) -> double
main(script, *args)
create the display and wait for user events
modf(...)
modf(x)
 
Return the fractional and integer parts of x.  Both results carry the sign
of x.  The integer part is returned as a real.
norm(...)
C++ signature:
    norm(boost::python::numeric::array) -> boost::python::api::object
 
Returns the unit vector of its argument.
C++ signature:
    norm(visual::vector) -> visual::vector
pow(...)
pow(x,y)
 
Return x**y (x to the power of y).
proj(...)
The vector projection of arg1 to arg2.
C++ signature:
    proj(visual::vector, visual::vector) -> visual::vector
radians(...)
radians(x) -> converts angle x from degrees to radians
rate(...)
Pause animation execution for 1/arg seconds.
C++ signature:
    rate(double) -> void*
reshape(...)
reshape(a, (d1, d2, ..., dn)).  Change the shape of a to be an n-dimensional array with dimensions given by d1...dn.  Note: the size specified for the new array must be exactly equal to the size of the  old one or an error will occur.
rotate(...)
C++ signature:
    rotate(visual::vector, double angle, visual::vector axis) -> visual::vector
 
rotate( vector, float angle, vector axis=vector(0,1,0)) -> vector
 Rotate a vector about an axis through an angle.
C++ signature:
    rotate(visual::vector, double angle) -> visual::vector
searchsorted = binarysearch(...)
binarysearch(a,v)
set_size(spheres, factor=0.69999999999999996)
for each sphere, find d, the distance to the nearest neighbor
and set radius = factor * d
take(...)
take(a, indices, axis=0).  Selects the elements in indices from array a along the given axis.
toggle_label(obj)
add or remove the label from a color sphere
zeros(...)
zeros((d1,...,dn),typecode='l',savespace=0) will return a new array of shape (d1,...,dn) and type typecode with all it's entries initialized to zero.  If savespace is nonzero the array will be a spacesaver array.

 
Data
        Character = 'c'
Complex = 'D'
Complex0 = 'F'
Complex16 = 'F'
Complex32 = 'F'
Complex64 = 'D'
Complex8 = 'F'
Float = 'd'
Float0 = 'f'
Float16 = 'f'
Float32 = 'f'
Float64 = 'd'
Float8 = 'f'
Int = 'l'
Int0 = '1'
Int16 = 's'
Int32 = 'i'
Int8 = '1'
LittleEndian = True
NewAxis = None
PyObject = 'O'
UInt = 'u'
UInt16 = 'w'
UInt32 = 'u'
UInt8 = 'b'
UnsignedInt16 = 'w'
UnsignedInt32 = 'u'
UnsignedInt8 = 'b'
UnsignedInteger = 'u'
absolute = <ufunc 'absolute'>
add = <ufunc 'add'>
arccos = <ufunc 'arccos'>
arccosh = <ufunc 'arccosh'>
arcsin = <ufunc 'arcsin'>
arcsinh = <ufunc 'arcsinh'>
arctan = <ufunc 'arctan'>
arctan2 = <ufunc 'arctan2'>
arctanh = <ufunc 'arctanh'>
bitwise_and = <ufunc 'bitwise_and'>
bitwise_or = <ufunc 'bitwise_or'>
bitwise_xor = <ufunc 'bitwise_xor'>
ceil = <ufunc 'ceil'>
conjugate = <ufunc 'conjugate'>
cos = <ufunc 'cos'>
cosh = <ufunc 'cosh'>
divide = <ufunc 'divide'>
divide_safe = <ufunc 'divide_safe'>
e = 2.7182818284590451
equal = <ufunc 'equal'>
exp = <ufunc 'exp'>
fabs = <ufunc 'fabs'>
false = 0
floor = <ufunc 'floor'>
floor_divide = <ufunc 'floor_divide'>
fmod = <ufunc 'fmod'>
greater = <ufunc 'greater'>
greater_equal = <ufunc 'greater_equal'>
hypot = <ufunc 'hypot'>
i = 'dot'
invert = <ufunc 'invert'>
left_shift = <ufunc 'left_shift'>
less = <ufunc 'less'>
less_equal = <ufunc 'less_equal'>
log = <ufunc 'log'>
log10 = <ufunc 'log10'>
logical_and = <ufunc 'logical_and'>
logical_not = <ufunc 'logical_not'>
logical_or = <ufunc 'logical_or'>
logical_xor = <ufunc 'logical_xor'>
maximum = <ufunc 'maximum'>
minimum = <ufunc 'minimum'>
multiply = <ufunc 'multiply'>
negative = <ufunc 'negative'>
not_equal = <ufunc 'not_equal'>
pi = 3.1415926535897931
power = <ufunc 'power'>
remainder = <ufunc 'remainder'>
right_shift = <ufunc 'right_shift'>
scene = <visual.ui.display object at 0x8248aa4>
sin = <ufunc 'sin'>
sinh = <ufunc 'sinh'>
sqrt = <ufunc 'sqrt'>
subtract = <ufunc 'subtract'>
tan = <ufunc 'tan'>
tanh = <ufunc 'tanh'>
true = 1
true_divide = <ufunc 'true_divide'>
typecodes = {'Character': 'c', 'Complex': 'FD', 'Float': 'fd', 'Integer': '1sil', 'UnsignedInteger': 'bwu'}
version = (3, 2, 9)