That's terrific Tom. I've been hoping this would be released soon. I've been looking forward to it.
Thanks, a lot of work has gone into this library. Although the library may initially appear more subtle and less wicked than for example Core Image, there's some great tools in there that dramatically increase the visual effect of compositions you create (I especially like analog colors, shades and shadows).
Have fun!
Hello,
I am currently poking around with the code for the Colors library, it looks really amazing... I haven't seen something that let's you do such nice operations on colors programmatically (and in Python no less).
My only problem is that since I do not have access to an OS X machine I can't actually run the code. I've had limited success by hacking up mock objects for some dependencies. I got all the way down to things like NSColor before I saw that wasn't really going to get me very far.
I've also tried rewriting certain functionality from scratch, which has been pretty good. I chose the theme loader as an initial goal, because it seems the most interesting. I have a rudimentary version of it running now.
My thought is... what do you think of freeing the Colors library from the Core Image dependencies? It seems useful for doing all kinds of things, more than just NodeBox's functionality on OS X provides (I'm dreaming of automatic generation of color schemes in CSS based on page content). I don't necessarily need a full blown port of NodeBox, the ability to play with colors would be great. The bonus of a platform independent color library means you could re-use it for other endeavors... I see the Java and .Net branches in svn :)
I figure it'd take a week to get a basic version that's roughly equivalent to the current version (minus any drawing features, which would be a whole 'nother project). Any tips or pointers on working with the code?
Looking at the code the separation can be fairly easy I think. You can wait a bit till I have the time to do it myself or you can get started on your own (I need to review the Graph library and a Perlin noise function first).
First, the library imports from nodebox.graphics, nodebox.util and AppKit so these import need to be try-expected. Then an alternative to the NodeBox random() command needs to be included (it takes a min and a max parameter).
Second, all commands that use _ctx (the NodeBox drawing context) won't work on other system but they can just keep being the way they are I think. These include outline(), shadow(), gradientpath(), colorwheel() and the swatch() and swarm() methods in the Color, ColorList and ColorRange classes.
This, the image_to_rgb() method in ColorList uses Core Image to find pixel color values. Perhaps when this doesn't work it can fall back to PIL (Python Imaging Library).
Most work will probably go into separating the Color class from NSColor. The Color class inherits from the nodebox.graphics.cocoa.Color class which builds on NSColor. So you will have to write a pure-Python alternative with r, g, b, c, m, y, k and h, s, b properties and the internal magic to keep those in synch.
This might get you started:
class Color: def __init__(self, r, g, b): self._r = r self._g = g self._b = b c, m, y, k = rgb2cmyk(r, g, b) self._c = c self._m = m self._y = y self._k = k def _get_c(self): return self._c def _set_c(self, v): self._c = max(0, min(v, 1)) r, g, b = cmyk2rgb(self._c, self._m, self._y, self._k) self._r = r self._g = g self._b = b c = cyan = property(_get_c, _set_c)I've included color space conversion commands (like rgb2cmyk) in the latest download of the library but these may be a bit naive, maybe you should google around for more robust conversion methods.
The yahoo() and morguefile() commands build on the NodeBox Web library but that one should already be cross-platform.
Best regards,
Tom
Hi Steve,
I've done the necessary modifications to make the library work outside of NodeBox. I did a few quick tests and everything seems to be working fine.
Color lists from image pixels will try to import PIL.
outline(), shadow(), gradientpath() won't work (but they don't make any sense outside of a drawing context so that's no problem).
Let me know if you run into any problems!
Outstanding work !! And outstanding documentation !!
Colors library
Posted by Tom De Smedt on Nov 12, 2007The new Colors library has finally been documented and can be downloaded here. Check it out!