Created
May 13, 2014 18:29
-
-
Save ecounysis/5d8865c565a72baabf3f to your computer and use it in GitHub Desktop.
static
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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