public void fillPolygon(Object graphics,int[] xPoints,int[] yPoints,int nPoints){
  int[] intersections=new int[nPoints];
  int intersectionsCount=0;
  int yMax=(int)yPoints[0];
  int yMin=(int)yPoints[0];
  for (int i=0; i < nPoints; i++) {
    yMax=Math.max(yMax,yPoints[i]);
    yMin=Math.min(yMin,yPoints[i]);
  }
  for (int row=yMin; row <= yMax; row++) {
    intersectionsCount=0;
    for (int i=1; i < nPoints; i++) {
      if (checkIntersection(graphics,row,xPoints[i - 1],xPoints[i],yPoints[i - 1],yPoints[i],intersections,intersectionsCount)) {
        intersectionsCount++;
      }
    }
    if (checkIntersection(graphics,row,xPoints[nPoints - 1],xPoints[0],yPoints[nPoints - 1],yPoints[0],intersections,intersectionsCount)) {
      intersectionsCount++;
    }
    for (int j=0; j < nPoints; j++) {
      if (row == yPoints[j]) {
        intersectionsCount+=markIntersectionEdge(graphics,j,yPoints,xPoints,nPoints,intersections,intersectionsCount);
      }
    }
    int swap=0;
    for (int i=0; i < intersectionsCount; i++) {
      for (int j=i; j < intersectionsCount; j++) {
        if (intersections[j] < intersections[i]) {
          swap=intersections[i];
          intersections[i]=intersections[j];
          intersections[j]=swap;
        }
      }
    }
    for (int i=1; i < intersectionsCount; i=i + 2) {
      drawLine(graphics,intersections[i - 1],row,intersections[i],row);
    }
  }
}

public void fillPolygon ( Object graphics , int [ ] xPoints , int [ ] yPoints , int nPoints ) { int [ ] intersections = new int [ nPoints ] ; int intersectionsCount = 0 ; int yMax = ( int ) yPoints [ 0 ] ; int yMin = ( int ) yPoints [ 0 ] ; for ( int i = 0 ; i < nPoints ; i ++ ) { yMax = Math . max ( yMax , yPoints [ i ] ) ; yMin = Math . min ( yMin , yPoints [ i ] ) ; } for ( int row = yMin ; row <= yMax ; row ++ ) { intersectionsCount = 0 ; for ( int i = 1 ; i < nPoints ; i ++ ) { if ( checkIntersection ( graphics , row , xPoints [ i - 1 ] , xPoints [ i ] , yPoints [ i - 1 ] , yPoints [ i ] , intersections , intersectionsCount ) ) { intersectionsCount ++ ; } } if ( checkIntersection ( graphics , row , xPoints [ nPoints - 1 ] , xPoints [ 0 ] , yPoints [ nPoints - 1 ] , yPoints [ 0 ] , intersections , intersectionsCount ) ) { intersectionsCount ++ ; } for ( int j = 0 ; j < nPoints ; j ++ ) { if ( row == yPoints [ j ] ) { intersectionsCount += markIntersectionEdge ( graphics , j , yPoints , xPoints , nPoints , intersections , intersectionsCount ) ; } } int swap = 0 ; for ( int i = 0 ; i < intersectionsCount ; i ++ ) { for ( int j = i ; j < intersectionsCount ; j ++ ) { if ( intersections [ j ] < intersections [ i ] ) { swap = intersections [ i ] ; intersections [ i ] = intersections [ j ] ; intersections [ j ] = swap ; } } } for ( int i = 1 ; i < intersectionsCount ; i = i + 2 ) { drawLine ( graphics , intersections [ i - 1 ] , row , intersections [ i ] , row ) ; } } }
fills a closed polygon defined by arrays of x and y coordinates . each pair of ( x , y ) coordinates defines a point .
