Skip to content

Instantly share code, notes, and snippets.

@ecounysis
Created May 13, 2014 22:54
Show Gist options
  • Save ecounysis/8b3cf91a684b5f98bb48 to your computer and use it in GitHub Desktop.
Save ecounysis/8b3cf91a684b5f98bb48 to your computer and use it in GitHub Desktop.
static in jython
from java.awt import Color
from javax.swing import JFrame
from java.awt.image import BufferedImage
from java.util import Random
from java.lang import Thread
def getBackground(WIDTH,HEIGHT,size):
rand=Random()
background = BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB)
bg2=background.getGraphics()
for x in range(0,WIDTH,size):
for y in range(0,HEIGHT,size):
r=rand.nextInt(255)
color=Color(r,r,r)
bg2.setColor(color)
bg2.fillRect(x,y,size,size)
return background
WIDTH=800
HEIGHT=600
size=6
a=JFrame()
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, None)
Thread.sleep(1000/60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment