Permalink
Browse files

explode example

  • Loading branch information...
1 parent 61a3576 commit 746bb2f4b720a1dff9bbae3b82014421477c1d40 @jdf committed Sep 8, 2010
@@ -0,0 +1,34 @@
+"""
+ Explode
+ by Daniel Shiffman.
+ (Rewritten in Python by Jonathan Feinberg.)
+
+ Mouse horizontal location controls breaking apart of image and
+ Maps pixels from a 2D image into 3D space. Pixel brightness controls
+ translation along z axis.
+ """
+
+cellsize = 2 # Dimensions of each cell in the grid
+img = loadImage("eames.jpg")
+columns = img.width / cellsize # Calculate # of columns
+rows = img.height / cellsize # Calculate # of rows
+def setup():
+ size(640, 360, P3D)
+
+def draw():
+ background(0)
+ for p in xrange(rows * columns):
+ x = cellsize * (p % rows) + cellsize / 2
+ y = cellsize * (p / rows) + cellsize / 2
+ loc = x + y * img.width # Pixel array location
+ c = img.pixels[loc] # Grab the color
+ # Calculate a z position as a function of mouseX and pixel brightness
+ z = (mouseX / float(width)) * brightness(img.pixels[loc]) - 20.0
+ # Translate to the location, set fill and stroke, and draw the rect
+ pushMatrix()
+ translate(x + 200, y + 100, z)
+ fill(c, 204)
+ noStroke()
+ rectMode(CENTER)
+ rect(0, 0, cellsize, cellsize)
+ popMatrix()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.

0 comments on commit 746bb2f

Please sign in to comment.