
import java.awt.*;
import objectdraw.*;

public class CompoundPiece extends ActiveObject implements PieceInterface {

        private static final int PAUSETIME = 400;
        private static final int PIECES = 6;

        private Location start;
        private double size, limit;
        private DrawingCanvas canvas;        // canvas to be drawn on
        private PieceInterface outerPiece;
        private Color color;
        private PieceInterface innerPieces[] = new PieceInterface[PIECES];
        
        public CompoundPiece(Location start, double size, double limit,
                                                Color color, DrawingCanvas canvas) {

                // create line which will later be replaced by "pushed" out figure
            outerPiece = new SimplePiece(start,size,color, canvas);
                this.limit = limit;
                this.start = start;
                this.size = size;
                this.color = color;
                this.canvas = canvas;
                start();
        }


        // After pause, start pushing line out into fractal pattern
        public void run() {

                pause(PAUSETIME);        

                double newSize = size/2;
                for (int i = 0; i < 6; i++) {
                Location pt = 
                    new Location(start.getX() + newSize/2 * Math.cos(i / 3.0 * Math.PI),
                                 start.getY() + newSize/2 * Math.sin(i / 3.0 * Math.PI));
                    if (newSize > limit) {
                        innerPieces[i] = new CompoundPiece(pt, newSize, limit, color, canvas);
                    } else {
                        innerPieces[i] = new SimplePiece(pt, newSize, color, canvas);
                    }
                }
        }
}
