Permalink
Browse files

improve examples formatting

  • Loading branch information...
1 parent d9647d3 commit 3fb764a23bf4eef4855633a4f695f93fa9985fb5 @jdf committed Sep 12, 2010
Showing with 22 additions and 21 deletions.
  1. +18 −17 examples.py/3D/Image/Explode.py
  2. +4 −4 examples.py/Topics/AdvancedData/directory_list.py
@@ -8,27 +8,28 @@
translation along z axis.
"""
-cellsize = 2 # Dimensions of each cell in the grid
+cellsize = 2 # Dimensions of each cell in the grid
img = loadImage("eames.jpg")
-columns = img.width / cellsize # Calculate # of columns
+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()
+ for row in range(rows):
+ for col in range(columns):
+ x = cellsize * col + cellsize / 2
+ y = cellsize * row + 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()
@@ -1,12 +1,12 @@
"""
* Listing files in directories and subdirectories
- * inspired by an example by Daniel Shiffman.
- *
+ * inspired by an example by Daniel Shiffman.
+ *
* 1) List the names of files in a directory
- * 2) List the names along with metadata (size, lastModified)
+ * 2) List the names along with metadata (size, lastModified)
* of files in a directory
* 3) List the names along with metadata (size, lastModified)
- * of files in a directory and all subdirectories (using recursion)
+ * of files in a directory and all subdirectories (using recursion)
"""
from datetime import datetime

0 comments on commit 3fb764a

Please sign in to comment.