/*
  Animation zur Aufgabe 2.03

 */
import java.awt.Color;
import java.lang.Math;

public class welle_2_03 extends PlotAnimation
{
    public double a0(double x)
    {
	if( Math.abs(x) < 1.0 )
	    {
		double a=x+1.0;
		double b=x-1.0;
		return a*a*b*b;
	    }
	else
	    return 0.0;
    }

    public double Integral_b0(double x)
    {
	if( x < 0.0  ) return 0.0;
	else if( x < 2.0 )
	    return x*x*x*(4.0/3.0+x*(-1.0+0.2*x));
	else return 16.0/15.0;
    }

    // Vorwaerts laufende Welle:
    public class Vorl extends Plot.PlotFunction
    {
	public Vorl(){color=Color.green;}
	public double fy(double x, double t)
	{
	    return 0.5*(a0(x-t)-Integral_b0(x-t));
	}
    }

    // Ruecklaufende Welle:
    public class Rueckl extends Plot.PlotFunction
    {
	public Rueckl(){color=Color.blue;}
	public double fy(double x,double t)
	{
	    return 0.5*(a0(x+t)+Integral_b0(x+t));
	}
    }

    // Resultierende Welle:
    public class Result extends Plot.PlotFunction
    {
	public double fy(double x,double t)
	{
	    return
		0.5*( a0(x-t) - Integral_b0(x-t) )
		+
		0.5*( a0(x+t) + Integral_b0(x+t) );
	}
    }


    // Konstruktor:
    public welle_2_03()
    {
	set_x_range(-3.0,3.0);
	set_y_range(-1.0,2.0);
	set_x_tics(-3.0,1.0);
	set_y_tics(-1.0,0.5);
	set_t_range(-3.0,3.0,0.07);
	graphs.addElement(new Vorl());
	graphs.addElement(new Rueckl());
	graphs.addElement(new Result());

	wave_action = NOT_RUNNING;
    }
}
