Is there any way to essentially "cut-out" a circle out of a black image?
What I want to do is create a solid black image that covers the world with a small circle of transparency around one object (or more). Any way of doing this?
public void light(int x, int y)
{
dark.clear();
dark.setColor(Color.BLACK);
dark.fillRect(0,0,dark.getWidth(),dark.getHeight());
dark.setColor(new Color(0,0,0,0));
dark.fillOval(x-5,y-5,x+5,y+5);
setImage(dark);
}GreenfootImage myImage = ...; BufferedImage myBuffer = myImage.getAwtImage(); Graphics2D myGraphics = myBuffer.createGraphics(); AlphaComposite compClear = AlphaComposite.CLEAR; myGraphics.setComposite(compClear); myGraphics.fillOval(...);
public void light(int x, int y)
{
GreenfootImage myImage = new GreenfootImage(600, 400);
java.awt.image.BufferedImage myBuffer = myImage.getAwtImage();
Graphics2D myGraphics = myBuffer.createGraphics();
AlphaComposite compClear = AlphaComposite.Clear;
myGraphics.setComposite(compClear);
myGraphics.fillOval(x-5,y-5,x+5,y+5);
setImage(dark);
}public void createPortal(int x, int y, int r) // x and y are the center and r is the radius
{
GreenfootImage img = getImage();
Color color = Color.white;
Color trans = new Color(0, 0, 0, 0);
img.setColor(color);
img.fillOval(x - r, y - r, r * 2, r * 2);
for (int i = 0; i < r * 2; i++)
{
for (int j = 0; j < r * 2; j++)
{
Color here = img.getColorAt(x - r + i, y - r + j);
if (color.equals(here)) img.setColorAt(x - r + i, y - r + j, trans);
}
}
setImage(img);
}