Skip to content

Instantly share code, notes, and snippets.

@ecounysis
Created May 13, 2014 18:29
Show Gist options
  • Save ecounysis/5d8865c565a72baabf3f to your computer and use it in GitHub Desktop.
Save ecounysis/5d8865c565a72baabf3f to your computer and use it in GitHub Desktop.
static
import java.awt.*;
import javax.swing.*;
import java.awt.image.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.Random;
public class Static extends JFrame
{
static int HEIGHT;
static int WIDTH;
public static void main(String[] args) throws Throwable
{
Graphics gr;
BufferedImage bg;
Static a = new Static();
/*
WIDTH=Integer.parseInt(args[0]);
HEIGHT=Integer.parseInt(args[1]);
int size=Integer.parseInt(args[2]);
*/
WIDTH=800;
HEIGHT=600;
int size=6;
a.setSize(WIDTH, HEIGHT);
a.setResizable(false);
a.setVisible(true);
a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gr = a.getGraphics();
while (true)
{
bg=getBackground(WIDTH,HEIGHT,size);
gr.drawImage(bg, 0, 0, null);
Thread.sleep(1000/100); // sleep a bit
}
}
static BufferedImage getBackground(int WIDTH, int HEIGHT, int size)
{
Random rand=new Random();
BufferedImage background = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
Graphics2D bg2 = (Graphics2D) background.getGraphics();
for (int x=0; x<WIDTH; x+=size) {
for (int y=0; y<HEIGHT; y+=size) {
int r=rand.nextInt(255);
Color color = new Color(r, r, r);
bg2.setColor(color);
bg2.fillRect(x,y,size,size);
}
}
return background;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment