FileDocCategorySizeDatePackage
RoundGradientContext.javaAPI DocExample1506Mon Apr 05 10:11:34 BST 1999None

RoundGradientContext

public class RoundGradientContext extends Object implements PaintContext

Fields Summary
protected Point2D
mPoint
protected Point2D
mRadius
protected Color
mC1
protected Color
mC2
Constructors Summary
public RoundGradientContext(Point2D p, Color c1, Point2D r, Color c2)

    mPoint = p;
    mC1 = c1;
    mRadius = r;
    mC2 = c2;
  
Methods Summary
public voiddispose()

public java.awt.image.ColorModelgetColorModel()

 return ColorModel.getRGBdefault(); 
public java.awt.image.RastergetRaster(int x, int y, int w, int h)

    WritableRaster raster =
        getColorModel().createCompatibleWritableRaster(w, h);
    
    int[] data = new int[w * h * 4];
    for (int j = 0; j < h; j++) {
      for (int i = 0; i < w; i++) {
        double distance = mPoint.distance(x + i, y + j);
        double radius = mRadius.distance(0, 0);
        double ratio = distance / radius;
        if (ratio > 1.0)
          ratio = 1.0;
      
        int base = (j * w + i) * 4;
        data[base + 0] = (int)(mC1.getRed() + ratio *
            (mC2.getRed() - mC1.getRed()));
        data[base + 1] = (int)(mC1.getGreen() + ratio *
            (mC2.getGreen() - mC1.getGreen()));
        data[base + 2] = (int)(mC1.getBlue() + ratio *
            (mC2.getBlue() - mC1.getBlue()));
        data[base + 3] = (int)(mC1.getAlpha() + ratio *
            (mC2.getAlpha() - mC1.getAlpha()));
      }
    }
    raster.setPixels(0, 0, w, h, data);
    
    return raster;