Open nasser opened 13 years ago
This could be done pretty easily by copying lib/core/color/hsv.rb. The algorithm is slightly different for converting to/from RGB, but it shouldn't be too bad. There are other examples on the net of algorithms for doing that.
In pseudocode, with horrible VB.NET examples: http://www.devx.com/tips/Tip/41581 Java examples: http://www.docjar.com/html/api/java/awt/Color.java.html
In each example, the underlying algorithm is essentially the same. Hue calculations shouldn't change at all, and brightness/saturation/value calculations are pretty basic. In most cases, it looks like you take the maximum of any of the RGB values and set that as the brightness value. And your saturation is the distance of your highest/lowest R, G, or B value away from the average of all three... I think. Again, I'd just convert an existing, working algorithm into Ruby. :-)
I'll bang this together
Not sure about the syntax. This OF forum post could serve as a jumping off point.