This looks really interesting! Thanks!

Eric.


Vincent Hardy <[EMAIL PROTECTED]> wrote:
Eric,

There is a radial gradient implementation in the GLF software that
you can download at:

http://java.sun.com/products/java-media/2D/samples/index.html

If you use the RadialGradientPaintExt in that software (a multicolor
radial gradient Paint), you can create a sphere effect on a circle.

I have put an example of how to create a sphere effect with that
gradient at the end of this email.

I hope this helps.
Regards.

Vincent Hardy.
Sun Microsystems.

> >At 11:24 AM 9/22/00 -0700, EEOAM wrote:
> > >Hi,
> > >
> > >does anyone know how I can draw a sphere with Java2D?
> > >
> > >Thanks,
> > >
> > >Eric M.
> > >

import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.*;
import com.sun.glf.goodies.*;

public class Sphere extends JComponent {
    public void paint(Graphics _g){
        Graphics2D g = (Graphics2D)_g;
        Dimension size = getSize();
        int sphereSize = size.width <= size.height? size.width :
size.height;
        Color highlightColor = new Color(255, 255, 50);
        Color midtoneColor = new Color(200, 160, 40);
        Color shadowColor = new Color(128, 30, 10);
        float highlightInterval = 2, midtoneInterval = 2;
        float shadowInterval = 2, blackInterval = 1;

        Ellipse2D sphere = new Ellipse2D.Float(0, 0, sphereSize,
sphereSize);
        Rectangle gradientRect = new Rectangle(-sphereSize/2,
-sphereSize/2,
                                               3*sphereSize/2,
3*sphereSize/2);

        Color gradientColors[] = {Color.white, highlightColor,
                                  midtoneColor, shadowColor,
Color.black};
        float gradientIntervals[] = {highlightInterval, midtoneInterval,
                                     shadowInterval, blackInterval};
        RadialGradientPaintExt sphereFilling
            = new RadialGradientPaintExt(gradientRect,
                                         gradientColors,
                                         gradientIntervals);

        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        g.setPaint(sphereFilling);
        g.fill(sphere);
    }

    public static void main(String args[]){
        JFrame frame = new JFrame();
        Sphere sphere = new Sphere();
        sphere.setPreferredSize(new Dimension(200, 200));
        frame.getContentPane().add(sphere);
        frame.getContentPane().setBackground(Color.white);

        frame.addWindowListener(new WindowAdapter(){
                public void windowClosing(WindowEvent evt){
                    System.exit(0);
                }
            });

        frame.pack();
        frame.setVisible(true);
    }
}

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".


____________________________________________________________________
Get your own FREE, personal Netscape WebMail account today at 
http://home.netscape.com/webmail

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to