Skip to main content

How to create a custom gradient (e.g, implement Paint)?

1 reply [Last post]
jvaudry
Offline
Joined: 2006-05-05

Hi,

I am trying to figure out how to create an elliptical gradient (i.e, instead of the color changing from point a to point b with a line function, the color changes from a center point, to a corner point, using an ellipse function).

I found the code to do a circle gradient, but now I need to adapt the logic to make it work for ellipses. Unfortunately, each time I change it, I cannot get the desired results. Here is the link to the code:

http://forum.java.sun.com/thread.jspa?threadID=778802

Any help is greatly appreciated.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Chris Campbell

In case you weren't aware, there is a new RadialGradientPaint class in
JDK 6 that should work for you. In particular, check out this
constructor, which allows you to specify the (rectangular) bounds of an
ellipse:
http://download.java.net/jdk6/docs/api/java/awt/RadialGradientPaint.html#RadialGradientPaint(java.awt.geom.Rectangle2D,%20float[],%20java.awt.Color[],%20java.awt.MultipleGradientPaint.CycleMethod)

Hope this helps,
Chris

java2d@javadesktop.org wrote:
> Hi,
>
> I am trying to figure out how to create an elliptical gradient (i.e, instead of the color changing from point a to point b with a line function, the color changes from a center point, to a corner point, using an ellipse function).
>
> I found the code to do a circle gradient, but now I need to adapt the logic to make it work for ellipses. Unfortunately, each time I change it, I cannot get the desired results. Here is the link to the code:
>
> http://forum.java.sun.com/thread.jspa?threadID=778802
>
> Any help is greatly appreciated.
> [Message sent by forum member 'jvaudry' (jvaudry)]
>
> http://forums.java.net/jive/thread.jspa?messageID=165778
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".