temp.smooth();
temp.translate(temp.width / 2, temp.height / 2);
temp.imageMode(PConstants.CENTER);
temp.image(img, 0, 0);
temp.endDraw();
PImage saveArea = p.createImage(temp.width, temp.height, PConstants.ARGB);
for (int y = 0; y < saveArea.height; y++) {
for (int x = 0; x < saveArea.width; x++) {
int index = y + x * saveArea.width;
float d = PApplet.dist(x, y, radius, radius);
if (d > radius) {
saveArea.pixels[index] = 0;
} else if (d >= radius - feather) {
int c = temp.pixels[index];
int r = (c >> 16) & 0xff;
int g = (c >> 8) & 0xff;
int b = (c) & 0xff;
c = p.color(r, g, b, PApplet.map(d, radius - feather, radius, 255, 0));
saveArea.pixels[index] = c;
} else {
saveArea.pixels[index] = temp.pixels[index];
}
}
}
saveArea.updatePixels();
return saveArea;
}