public java.awt.image.Raster | getRaster(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;
|