Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Initial port of Goop.java, not fully moved over and serious performance issues
#!/usr/bin/env python
import random
from pyglet.image import ImageData
from pyglet.window import *
w = 320
h = 320
window = pyglet.window.Window()
window.set_size(w,h)
img = pyglet.image.create(w,h)
data = [int(255*random.random()) for i in xrange(w*h*4)]
def goop(dt):
global img
global data
for i in range(w*2,(w*h*4)-w*2):
if int(500*random.random()) < 1:
r = int(255*random.random())
data[i] = r
data[i-1] = r
data[i-2] = r
data[i-3] = r
data[i-4] = r
d = data[i]
d += data[i + 4]
d += data[i - 4]
d += data[i - 8]
d += data[i + 8]
d += data[i - w]
d += data[i + w]
d = d / 7
if(data[i] > 150):
d += data[i + w * 2]
d = d / 2
data[i + w * 2] = d
data[i + w] = d
elif(data[i] < 125):
d += data[i - w * 2]
d = d / 2
data[i - w * 2] = d
data[i - w] = d
data[i] = d
@window.event
def on_draw():
window.clear()
global img
global data
img.set_data('RGBA',w*4,''.join(map(chr, data)));
img.blit(0,0,0)
pyglet.clock.schedule_interval(goop, .1)
pyglet.app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment