Animated Client Background
Code:
package graphics;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ConvolveOp;
import java.awt.image.Kernel;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
public class BubbleCell {
public ArrayList<BubbleCell> cells;
private float[] data = new float[500];
public BubbleCell(int amount)
{
Arrays.fill(data, 1f / 20f);
cells = new ArrayList<>(amount);
for (int i = 0; i < amount; i++)
{
int baseSpeed = grabRandom(0, 1);
int xSpeed = (int) Math.floor((Math.random() * (baseSpeed - -baseSpeed + baseSpeed)) + -baseSpeed);
int ySpeed = (int) Math.round((Math.random() * baseSpeed) + 0.5);
int radius = grabRandom(50, 110);
int x = (int) Math.floor(Math.random() * getWidth());
int y = (int) Math.floor(Math.random() * getHeight());
int blurrAmount = (int) (Math.floor(Math.random() * 10) + 5);
int alpha = (int) ((Math.random() * 15) + 3);
Kernel kernel = new Kernel(blurrAmount, blurrAmount, data);
BufferedImageOp op = new ConvolveOp(kernel);
BufferedImage circle = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB);
Graphics2D circlegfx = circle.createGraphics();
circlegfx.setColor(new Color(grabRandom(0, 255), grabRandom(0, 255), grabRandom(0, 255), alpha));
circlegfx.fillOval(20, 20, radius, radius);
circle = op.filter(circle, null);
BubbleCell bubble = new BubbleCell(x, y, xSpeed, ySpeed, radius, grabRandom(0, 3), circle);
cells.add(bubble);
}
}
private int x, y, xSpeed, ySpeed, radius, direction;
private BufferedImage image;
public BubbleCell(int x, int y, int xSpeed, int ySpeed, int radius, int direction, BufferedImage image)
{
this.x = x;
this.y = y;
this.xSpeed = xSpeed;
this.ySpeed = ySpeed;
this.radius = radius;
this.direction = direction;
this.image = image;
}
public void process(Graphics g)
{
switch (direction) {
case 0:
moveRight();
break;
case 1:
moveLeft();
break;
case 2:
moveUp();
break;
case 3:
moveDown();
break;
}
g.drawImage(image, x, y, null);
}
private void moveUp()
{
x += xSpeed;
y -= ySpeed;
if (y + (radius / 2) < 0)
{
y = getHeight() + (radius / 2);
x = (int) Math.floor(Math.random() * getWidth());
}
if ((x + radius / 2) < 0 || (x - radius / 2) > getWidth())
{
y = radius + (radius / 2);
x = (int) Math.floor(Math.random() * getWidth());
}
}
private void moveDown()
{
x += xSpeed;
y += ySpeed;
if (y - (radius / 2) > getHeight())
{
y = 0 - (radius / 2);
x = (int) Math.floor(Math.random() * getWidth());
}
if ((x + radius / 2) < 0 || (x - radius / 2) > getWidth())
{
y = getHeight() + (radius / 2);
x = (int) Math.floor(Math.random() * getWidth());
}
}
private void moveRight()
{
x += ySpeed;
y += xSpeed;
if (y - (radius / 2) > getHeight() || y + (radius / 2) < 0)
{
x = 0 - (radius / 2);
y = (int) Math.floor(Math.random() * getHeight());
}
if ((x - radius / 2) > getWidth())
{
x = 0 - (radius / 2);
y = (int) Math.floor(Math.random() * getWidth());
}
}
private void moveLeft()
{
x -= ySpeed;
y -= xSpeed;
if (y - (radius / 2) > getHeight() || y + (radius / 2) < 0)
{
x = getWidth() + (radius / 2);
y = (int) Math.floor(Math.random() * getHeight());
}
if ((x + radius / 2) < 0)
{
x = getWidth() + (radius / 2);
y = (int) Math.floor(Math.random() * getWidth());
}
}
private int grabRandom(int min, int max)
{
SecureRandom secureRandom = new SecureRandom();
final int n = Math.abs(max - min);
return Math.min(min, max) + (n == 0 ? 0 : secureRandom.nextInt(n));
}
public int getWidth()
{
return 765;
}
public int getHeight()
{
return 503;
}
}
add this somewhere
Code:
Graphics2D g2d = (Graphics2D) super.graphics;
bubbleCell = new BubbleCell(20);
and this somewhere thats called on loop ie drawloginscreen
Code:
super.graphics.setColor(Color.black);
super.graphics.fillRect(0, 0, 765, 503);
for (int i = 0; i < bubbleCell.cells.size(); i++) {
BubbleCell cell = bubbleCell.cells.get(i);
cell.process((Graphics2D) super.graphics);
}
result
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]