FileDocCategorySizeDatePackage
Ellipses.javaAPI DocExample3764Wed Aug 08 15:13:48 BST 2001demos.Arcs_Curves

Ellipses

public class Ellipses extends AnimatingSurface
Ellipse2D 25 animated expanding ellipses.

Fields Summary
private static Color[]
colors
private Ellipse2D$Float[]
ellipses
private double[]
esize
private float[]
estroke
private double
maxSize
Constructors Summary
public Ellipses()



      
        setBackground(Color.black);
        ellipses = new Ellipse2D.Float[25];
        esize = new double[ellipses.length];
        estroke = new float[ellipses.length];
        for (int i = 0; i < ellipses.length; i++) {
            ellipses[i] = new Ellipse2D.Float();
            getRandomXY(i, 20 * Math.random(), 200, 200);
        }
    
Methods Summary
public voidgetRandomXY(int i, double size, int w, int h)

        esize[i] = size;
        estroke[i] = 1.0f;
        double x = Math.random() * (w-(maxSize/2));
        double y = Math.random() * (h-(maxSize/2));
        ellipses[i].setFrame(x, y, size, size);
    
public static voidmain(java.lang.String[] argv)

        createDemoFrame(new Ellipses());
    
public voidrender(int w, int h, java.awt.Graphics2D g2)

        for (int i = 0; i < ellipses.length; i++) {
            g2.setColor(colors[i%colors.length]);
            g2.setStroke(new BasicStroke(estroke[i]));
            g2.draw(ellipses[i]);
        }
    
public voidreset(int w, int h)

        maxSize = w/10;
        for (int i = 0; i < ellipses.length; i++ ) {
            getRandomXY(i, maxSize * Math.random(), w, h);
        }
    
public voidstep(int w, int h)

        for (int i = 0; i < ellipses.length; i++) {
            estroke[i] += 0.025f;
            esize[i]++;
            if (esize[i] > maxSize) {
                getRandomXY(i, 1, w, h);
            } else {
                ellipses[i].setFrame(ellipses[i].getX(), ellipses[i].getY(),
                                     esize[i], esize[i]);
            }
        }