nasser / zajal

Experimental creative coding framework
MIT License
161 stars 10 forks source link

Support HSB Colors #3

Open nasser opened 13 years ago

nasser commented 13 years ago

Not sure about the syntax. This OF forum post could serve as a jumping off point.

judy-zz commented 12 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.

nasser commented 12 years ago

Maybe http://ariya.blogspot.com/2008/07/converting-between-hsl-and-hsv.html ?

judy-zz commented 12 years ago

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. :-)

nasser commented 12 years ago

I'll bang this together