これを行う別の方法は、2 つのパスを使用して、イメージを別の方法でブレンドすることです。最初のパスでは、白 - 緑 - 透明度から、黒い四角形に複数の放射点を追加するだけです。
次に、同じポイントで、ステップ 1 の最初の画像を XOR ブレンディングで掘り下げました。
結果:
http://img11.imageshack.us/img11/7066/step3yr.png
コード:
public void creerLightMap(){
lightMap = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = lightMap.createGraphics();
g.setColor(Color.BLACK);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
float radius = 100;
//create color circle
for(int i=0; i<lumiere.size(); i++){
Point2D center = lumiere.get(i);
float[] dist = {0.0f, 0.5f, 1.0f};
Color[] colors = {new Color( 1.0f , 1.0f , 1.0f , 1.0f), new Color( 0.0f , 1.0f , 0.0f , 0.5f) , new Color( 0.0f , 1.0f , 0.0f , 0.0f)};
RadialGradientPaint p = new RadialGradientPaint(center, radius, dist, colors);
g.setPaint(p);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
}
//add an alpha into theses same circle
for(int i=0; i<lumiere.size(); i++){
Point2D center = lumiere.get(i);
float[] dist = {0.0f, 1.0f};
Color[] colors = {new Color( 1.0f , 1.0f , 1.0f , 1.0f) , new Color( 1.0f , 1.0f , 1.0f , 0.0f)};
RadialGradientPaint p = new RadialGradientPaint(center, radius, dist, colors);
g.setComposite(AlphaComposite.getInstance(AlphaComposite.XOR, 1.0f));
g.setPaint(p);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
}
g.dispose();
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.drawImage(this.lightMap, 0, 0, null);
}