// File:  FishPlus.java

import java.awt.*;
import java.applet.*;

public class FishPlus extends Applet {

    public void init() {
        // draw the background
        setBackground(new Color(140, 140, 255));
    }

    public void paint(Graphics g) {
        drawOcean(g);
        drawFish(g);
        // create and draw five Triangles
        for (int i = 0; i < 5; i++) {
            Triangle triangle = new Triangle(5 + (int) (25 * Math.random()));
            triangle.draw(g, 80 + 60*i, 220);
        }
        showStatus(" Refresh this applet or resize it slightly...");
    }

    private void drawOcean(Graphics g) {
        // draw the ocean bottom
        g.setColor(new Color(80, 80, 30));
        g.fillRect(0, 210, 400, 40);
        // draw the shield and text
        g.setColor(Color.black);
        g.fillRect(45, 35, 58 , 22);
        g.setColor(Color.white);
        g.drawString("FishPlus", 50, 50);
    }

    private void drawFish(Graphics g) {
        // draw the body
        g.setColor(Color.black);
        g.drawArc(100, 100, 200, 100,  5,  145);
        g.drawArc(100,  50, 200, 100, -5, -145);
        g.drawLine(300, 105, 300, 145);
        // draw the mouth
        g.drawArc(58, 37, 150, 100, -60, -30);
        // draw dorsal fin
        g.drawArc(182, 68, 150, 100, 110, 50);
        g.drawArc(218, 50, 150, 100, 144, 37);
        // draw ventral fin
        g.drawArc(190, 69, 120, 100, 220, 45);
        g.drawArc(231, 115, 60,  60, 185, 45);
        // draw the eye
        g.setColor(Color.blue);
        g.fillOval(140, 115, 18, 10);
    }

}   

class Triangle {

    Triangle(int nWid) {
        // save the width for this triangle
        nWidth = nWid;
    }

    public void draw(Graphics g, int x, int y) {
        // create a height that is 5/2 of the width
        int nHeight = (5 * nWidth) / 2;
        g.setColor(Color.white);
        // draw the three sides of this triangle
        g.drawLine(x-nWidth, y, x, y-nHeight);
        g.drawLine(x, y-nHeight, x+nWidth, y);
        g.drawLine(x-nWidth, y, x+nWidth, y);
    }

    private final int nWidth;       // width of this triangle
}

