package exercises;

import figure.*;
import java.awt.*;
import javax.swing.*;

public class ParabolasApplet extends JApplet implements Function {
    double[][] points = { {-1, 2}, {-0.5, -1}, {1, 0}, {0, 1.5}, 
			  {1.5, -0.5}, {-1.5, -0.5}};
    double l = -1.5;
    public void init() {
	setBackground(Color.white);
	FigurePanel panel = new FigurePanel(-2, -3, 2, 3);
	getContentPane().add(panel);

        Grid grid = new Grid();
        grid.setColor(Color.lightGray);
        panel.add(grid);
        
        Axes axes = new Axes();
        panel.add(axes);

	Color pointColor = new Color(1f, 0.3f, 0.3f);
	Color graphColor = new Color(0.5f, 0.5f, 1f);
	for (int i = 0; i < points.length; i++) {
	    GraphicalPoint gp = new GraphicalPoint(points[i][0], points[i][1]);
	    gp.setSize(2);
	    gp.setStyle(GraphicalPoint.CIRCLE);
	    gp.setColor(pointColor);
	    panel.add(gp);

	    GraphicalFunction gf = new GraphicalFunction(this, points[i]);
	    gf.setSteps(25);
	    gf.setColor(graphColor);
	    panel.add(gf);
	}

	BoundingBox bbox = panel.getBoundingBox();
	GraphicalLine line = new GraphicalLine(bbox.llx, l, bbox.urx, l);
	line.setColor(Color.red);
	line.setStroke(new BasicStroke(2));
	panel.add(line);
    }
	
    public double valueAt(double x, double[] params) {
        return (x-params[0])*(x-params[0])/(2*(params[1]-l)) +
	    (params[1]+l)/2;
    }

}


