This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HSV gradient

 
Steven Sørensen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there.
I'm having a bit of trouble finding a way to generate an HSV gradient...
sRGB and Linear RGB gradients are simple enough, as they're predefined in the java.awt.MultipleGradientPaint class and whatnot. But I can't for the life of me find a way to use the HSV (or HSB or HSL) colorspace to blend two colors. (And frustratingly, java.awt.color.ColorSpace isn't implemented out-of-the-box for common colorspaces. Arg.)

RGB gradient? Easy enough, it's implied:

But the HSV colorspace? There certainly doesn't seem to be any obvious way to to use it. Am I missing something right in front of me?

The best I could dig up with Google was this page: http://users.erols.com/ziring/java-samp-jgd.html It's pretty good, and the source code is very clean, but it's doesn't use the java.awt.Paint interface. I'm not sure how to retrofit it with Graphics2D compatibility.
Everything else I saw on Google was trivial algorithms to convert one colorspace to another. Not helpful.

Any pointers?



Edit: Okay, now this is extra sad. This post comes up in spot #1 in a Google search for java gradient hsb OR hsv OR hsl ...
 
Steven Sørensen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
URGENT!!! plz sir send teh codez god bless

Or "bump" or something.

I'm guessing this means there isn't a nice built-in way to create these gradients...
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://faq.javaranch.com/java/PatienceIsAVirtue
(I'll ignore the mistyped words since that was obviously meant as a joke )
 
Campbell Ritchie
Sheriff
Pie
Posts: 50251
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was 1½ weeks before he asked for a bump, Rob.

You can convert HSB to RGB with methods in the Color class; you might be able to use those to pass H, S and B values to Color objects and use those objects. Another Color link here.
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:It was 1½ weeks before he asked for a bump, Rob.

You're right, it should have been Ease Up. My bad.
 
Steven Sørensen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I know bumping isn't considered good form, but I've lurked* here for a while and seen it accepted, so I thought I'd give it a shot.
(*Unintentionally: Google often correctly suggests this place for the solutions to a quite a number of problems I've run into. So kudos for that.)

Campbell Ritchie wrote:You can convert HSB to RGB with methods in the Color class; you might be able to use those to pass H, S and B values to Color objects and use those objects. Another Color link here.


I have tried that, but actually it's just for converting values into the Color class's RGB storage form. (I checked the source code to be sure!) The GradientPaint class is what does the blending dirty work.
Just yesterday I started playing around with the Processing framework/library/API/whathaveyou. It's pretty great and has a really easy-to-use (read: made-for-n00bs) color handling that can easily blend on in HSB space.
Although I'm a bit disappointed that there seems to be no out-of-the-box Java way of doing this, I'll be using the Processing methods from now on, which are entirely sufficient.
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steven Sørensen wrote:Yeah, I know bumping isn't considered good form, but I've lurked* here for a while and seen it accepted, so I thought I'd give it a shot.

Bumping is allowed after 24 hours, but the "URGENT" was what I wanted to address. I just posted the wrong link.
 
Scott Phan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's an example of an HSV gradient track I wrote using the relationships between RGB and HSV found here: Wiki (HSV and HSL)

 
eric aro
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is my best solution :

Override GradientPaint (easy part) to HSVGradientPaint
copy paste/ GradientPaintContext into HSVGradientPaint (easy part)

there is an ugly code from sun that I can't get rid of (if someone has a deep knowledge on how to work on raster ...)

and replace the interp array filling (in the construcor) with one that matches HSV color.

here is the master piece, use this function to fill the "interp" array instead of the original code.


and BTW I would realllllllly like to find a better solution.

eric

(ps: attachement does not work, here is a copy paste of the whole solution )
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic