Skip to content

Instantly share code, notes, and snippets.

Last active December 15, 2015 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsundram/5332259 to your computer and use it in GitHub Desktop.
Save jsundram/5332259 to your computer and use it in GitHub Desktop.
Ported from my cleanup ( of analogpixel's sketch: About as straighforward a translation of processing into nodebox as possible.
from import *
from numpy.random import randint # random.randint is v. slow
import numpy
MINS, MAXS = 1, 40
grow = False
box_size = MAXS
counter = 1
# Use a numpy array of pixels because pic.get is too slow.
pic = Pixels(Image('pic.jpg'))
pixels = numpy.empty((pic.width, pic.height), dtype=Color)
for x in range(0, pic.width):
for y in range(0, pic.height):
pixels[x][y] = pic.get(x, y)
def setup():
canvas.fps = 30 # pipe dream, each frame takes a while.
canvas.size = pic.size
def draw(canvas):
global box_size, grow
box_size += 1 if grow else -1
if box_size <= MINS:
grow = True
elif MAXS <= box_size:
grow = False
def make(i):
global counter, pixels
for cc in xrange(pic.width * pic.height / 2):
x = randint(0, pic.width)
y = randint(0, pic.height)
rect(x, y, randint(MINS, i+1), randint(MINS, i+1), fill=pixels[x][y])
# Would love to use canvas.frame, but it doesn't advance properly'nb/image%03d.png' % counter)
print canvas.profiler.framerate
counter += 1
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment