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?


1 2 3 4 5 6 7 8 9 | 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); } |
1 2 3 4 5 6 7 | GreenfootImage myImage = ...; BufferedImage myBuffer = myImage.getAwtImage(); Graphics2D myGraphics = myBuffer.createGraphics(); AlphaComposite compClear = AlphaComposite.CLEAR; myGraphics.setComposite(compClear); myGraphics.fillOval(...); |
1 2 3 4 5 6 7 8 9 10 11 | 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); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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); } |