

package DDrawing;

import java.awt.Point ;
import java.awt.Color ;
import java.awt.Graphics ;


public class DFunction extends DComponent{

  public boolean isDefinedOn( double source ){ return true; }
  public double getSourceOf( double image ){ return image; }
  public double getImageOf( double source ){ return source; }

  public void paint( DMeasures m ){
    Graphics g = m.getGraphics();
    Color old_color = g.getColor();
    g.setColor( color );
    DRectangle rect = m.getDRectangle();
    double d_width = rect.width;
    int width = m.getPoint( d_width, 0 ).x - m.getPoint( 0, 0 ).x;
    Point p1 = null, p2;
    for( int i=0; i<width; i++ ){
      double x = rect.y + d_width / (double)i, y;
      if( isDefinedOn( x ) ){
        y = getImageOf( x );
        p2 = m.getPoint( x, y );
        if( p1 != null ) g.drawLine( p1.x, p1.y, p2.x, p2.y );
        p1 = p2;
      }
      else p1 = null;
    }
  }
}