
/**
 * Triangle.java
 *
 *
 * Created: Tue Dec 18 04:46:55 2001
 *
 * @author <a href="mailto: "Jan Newmarch</a>
 * @version
 */

package saver.drawable;

import java.awt.*;

public class Triangle extends Drawable{
    
    protected static Color[] colors = {Color.red, Color.blue, Color.green, Color.yellow};
    protected Color color;

    public Triangle() {
	int index = (int) Math.floor(Math.random() * colors.length);
	color = colors[index];
	setSize(20, 20);
    }

    public Triangle(Triangle orig) {
	super(orig);
	this.color = orig.color;
    }

    public void paint(Graphics g) {
	g.setColor(color);
	int h = this.getHeight();
	int w = this.getWidth();
	Polygon poly = new Polygon(new int[] {0, 0, w},
				   new int[] {0, h, h/2},
				   3);
	g.fillPolygon(poly);
	// System.out.println("painting");
    }

    public Drawable copy() {
	Triangle copy = new Triangle(this);
	copy.color = color;
	return copy;
    }
}// Triangle
